xxxxxxxxxx
function filteredArray(arr, elem) {
let newArr = [];
// Only change code below this line
for (let i = 0; i < arr.length; i++) {
if (arr[i].indexOf(elem) === -1) {
newArr.push(arr[i]);
}
}
// Only change code above this line
return newArr;
}
console.log(filteredArray([["amy", "beth", "sam"], ["dave", "sean", "peter"]], "peter"));
xxxxxxxxxx
Create a loop that runs through each item in the "fruits" array.
var fruits = ['Apple', 'Banana', 'Orange']
for(x of fruits){
console.log(x);
}
xxxxxxxxxx
var arr = [10, 9, 8, 7, 6];
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
xxxxxxxxxx
for( var i = 0, len_i = json.length; i < len_i; i++ ) {
for( var j = 0, len_j = json[ i ].length; j < len_j; j++ ) {
// do something with json[ i ][ j ]; (the value in the inner Array)
}
}
xxxxxxxxxx
var total = 0;
for (var i = 0; i < myArr.length; i++) {
total += myArr[i];
}
xxxxxxxxxx
var keys = Object.keys(o); // Get an array of property names for object o
var values = [] // Store matching property values in this array
for(var i = 0; i < keys.length; i++) { // For each index in the array
var key = keys[i]; // Get the key at that index
values[i] = o[key]; // Store the value in the values array
}
xxxxxxxxxx
let total = 0;
for (let i = 0; i < myArr.length; i++) {
total += myArr[i];
}