Linked Questions
323 questions linked to/from Loop through an array in JavaScript
10
votes
6
answers
11k
views
Looping through elements of an array in Javascript [duplicate]
I have an array in Javascript:
var array = new array();
array[0] = "apples";
array[1] = "oranges";
array[2] = "pears";
In PHP, with a given array, I can use the following to loop through an array, ...
9
votes
4
answers
12k
views
How to make simple php's foreach equivalent in Javascript? [duplicate]
Possible Duplicate:
Loop through array in JavaScript
I want to make the equivalent of php's foreach in javascript. Because I don't really know the Javascript language, I'd like someone to rewrite ...
5
votes
2
answers
5k
views
Remove attribute from JSON objects in a array [duplicate]
I have an array of json objects.
var user =[ { id: 1, name: 'linto', img: 'car' },
{ id: 2, name: 'shinto', img: 'ball' },
{ id: 3, name: 'hany', img: 'kite' } ]
From this is want to remove ...
12
votes
3
answers
2k
views
How would I loop over a group of JS objects and print a statement for each? [duplicate]
var teams = [
{
city: 'Vancouver',
nickname: 'Canucks',
league: 'NHL'
},
{
city: ...
3
votes
3
answers
5k
views
How can I get the position of an object during map function? [duplicate]
When you use for function you can save the position of an object like (example):
for (var i = 0; i < array.length; i++) {
var position = i;
}
but I don't know how I can get the position an ...
4
votes
2
answers
3k
views
How to loop through a list of static values (constants) in JavaScript? [duplicate]
How to loop through a fixed (development time) list of values in JavaScript?
In Perl, I'd do:
for my $item ('foo', 'bar', 'baz') {
which would run the loop with foo, bar and baz in $item (one each ...
-2
votes
1
answer
6k
views
loop through nested object properties [duplicate]
I am trying to check for an empty value in a nested object, how would I loop through the nested properties?
for (var propt in updatedInputs) {
if (updatedInputs[propt] == "") this.cancelSubmit();
...
6
votes
2
answers
964
views
How do I reference the string in a array of strings? [duplicate]
I have the following:
var tags = ["Favorite", "Starred", "High Rated"];
for (var tag in tags) {
console.log(tag);
}
Output is
0
1
2
I'd like it to output:
Favorite
Starred
High Rated
How do ...
-4
votes
2
answers
366
views
creating an array with a for statement [duplicate]
trying to create Create an array containing the names of at least three (3) fast food items and then, using a ‘for’ loop, display the array name, index number, and food item as shown below.
...
-5
votes
2
answers
542
views
How to loop iterate single value with array? [duplicate]
How do I achieve this in Javascript?
My problem is e.g.
templateMonth (string/single line value); templateName (array value)
const a = 2022-01
const b = ['HD-HD1460', 'HD-WHITE', 'HD-YHS']
My desired ...
4
votes
2
answers
786
views
Looping through jsonp with jquery [duplicate]
I can see the response is correct in firebug but cant actually access the data it returns - need a pointer. I am of course trying to put the timestamp of an entry into a div - the div does exist.
...
-2
votes
1
answer
942
views
getElementsbyClassName to find and act on all elements [duplicate]
Can't quite get this code to enact on all elements within my html - I know [0] means just one - but the code doesn't work without it as its raw js
window.onload = function yourFunction(){
var str ...
4
votes
2
answers
567
views
Read through JSON number array using javascript loop [duplicate]
I`m trying to write a loop that will read through a nested number array.
The JSON file that I`m reading goes like this. each number key represents event dates.
json reference for startdate and end ...
10
votes
1
answer
251
views
Javascript using constructor inside in Array [duplicate]
I have code like this, then I was confused on how to loop the array family
to print each member under person.
function Person(name,age){
this.name = name;
this.age = age;
}
var family = [];
...
7
votes
2
answers
233
views
How can I iterate over an array that is accesed by a key in a json Object [duplicate]
This is my stringified JSON object:
{
"bookingsList": [{
"bookingID": 5,
"destination": "BSO",
"flightDate": "2015-12-07T00:00:00",
"flightScheduleId": 113,
...