Display Ads after every nth iteration in #each MeteorJs [duplicate] - javascript

This question already has answers here:
Meteor - #each iteration of an array with another HTML element inserted after each nth item
(2 answers)
Closed 6 years ago.
I'm quite new to meteor blaze. I want to know how it's possible to display something (an advert) after a particular number of iteration in meteorjs. Any ideas? Thanks in advance.

And what about doing this within the js helper? I did it in this way.
Template.foo.helpers({
stuffWithAds : function(){
col = GivenCollection.find().fetch();
toTemplate = [];
for(i=0; i<col.length; i++){
toTemplate.push(col[i]);
if (i % 2 != 0){
toTemplate.push('whatever you want to insert');
}
}
return toTemplate; }
});
This inserts whatever you want after 2 elements.

Related

Remove row if value equal to [duplicate]

This question already has answers here:
Looping through array and removing items, without breaking for loop
(17 answers)
Remove items from array with splice in for loop [duplicate]
(5 answers)
Closed 2 years ago.
I am trying to remove all the rows that don't have the value '2A' or '2B' but whenever I execute the code it deletes every row except the first one.
Here is my bit of code :
function supprimerColonnesInutiles() {
for(i = 1; i < data.length; i++) {
if(data[i][13] === '2019-09-30'){
data.splice(i);
}
if(data[i][2] !== '2A'){
data.splice(i);
}
}
}
This code works perfectly to delete every row with the 2019 date but fails to do what I expect it to do to delete rows that contain 2A as a value (i'd like to keep 2B values as well).
here is the csv file that serves as my array, as you can see the second column contains 2As and 2Bs but also number from 1 to 100.
This is what I get if I execute the code enter image description here
and here is my csv/array enter image description here
My question is what could be causing this issue and how can I fix it ?

how to push object into an nested array within a loop? [duplicate]

This question already has answers here:
Push is overwriting previous data in array
(2 answers)
Closed 2 years ago.
I am using an angularjs foreach and want to find data objects to load into another objects array.
When doing this, it seems like I am adding the variable and all the added objects change to the last variable values.
var p = {};
angular.forEach(d, function(personnel, index){
if(wo.doc.job === personnel.job){
p["EmployeeID"] = personnel.EmployeeID;
p["Number"] = personnel.Number;
wo.doc.personnel.push(p);
console.log(personnel);
}
});
If this finds to 2 employees for a job, they are added and as i watch the wo.doc object after the second object is added the 2 added objects are the same as the last object.
Make a new object in the loop.
angular.forEach(d, function(personnel, index){
if(wo.doc.WorkOrderDetailID === personnel.PrimeWorkOrderNum){
var p = {EmployeeID: personnel.EmployeeID, Number: personnel.Number};
wo.doc.personnel.push(p);
}
});

Javascript Exploring an Element's Children [duplicate]

This question already has an answer here:
How can I iterate through an Elements child nodes using Javascript?
(1 answer)
Closed 4 years ago.
So lets say I have an element that contains this:
How would I be able to run through all these children in javascript?
Use querySelectorAll (which can be directly iterated over, unlike the HTMLCollection methods):
document.querySelectorAll('table.table').forEach(table => {
// do something with each table
});
To iterate over tables seems not useful but here it is. Note I am using the class name for your tables above to find each one. If your example had different classes for each table this would not work.
var tables = document.getElementsByClassName("table");
var arr = new Array();
for (i = 0; i < tables .length; i++) {
//do what you want here
}
If you want to work with the rows and cells within a table you might want to refer to this solution.

Loop through Drop Down Option and read its attribute using jquery [duplicate]

This question already has answers here:
How to get the attributes of a HTML element using JQuery?
(4 answers)
Closed 8 years ago.
I am looping through drop down option and checking attribute.
if attribute match than counter is increase. At the end i show counter as alert.
This is my code but some how its not working dont know why
var count= 0;
$('.mydropdown option').each(function () {
var level = this.attr("myattr");
if (level == "0") {
count++;
}
});
alert(count);
}
this is a plain javascript object, it does not contain a function called .attr()
Try,
var level = $(this).attr("myattr");
Just convert the this reference into a jquery object and invoke .attr() over it

.find('.foo').text() as array [duplicate]

This question already has answers here:
Get array of text values using selector instead of iterating?
(7 answers)
Closed 9 years ago.
I have html with multiple things classed .text. I the perform
console.log($(whatever).find('.foo').text());
The result is a textstring with all the contents in it. Can I save it to an array instead somehow?
You can use the map method to get this done
var textArray = $(whatever).find('.foo').map(function() {
return $(this).text();
}).get();
This will get you an array.. If you want to display it as a string then just use join along with it.
Check Fiddle
var arr = [];
$(whatever).find('.foo').each(function() {
arr.push($(this).text());
});

Categories

Resources