Is it possible to iterate over the array, excluding the first element (omit the first object in the array)?
CODE:
let multipleDemo =[];
let people = [
{ name: 'Adam', email: '[email protected]', age: 12,
country: 'United States' },
{ name: 'Amalie', email: '[email protected]', age: 12,
country: 'Argentina' },
{ name: 'Estefanía', email: '[email protected]', age: 21,
country: 'Argentina' },
{ name: 'Adrian', email: '[email protected]', age: 21,
country: 'Ecuador' },
{ name: 'Wladimir', email: '[email protected]', age: 30,
country: 'Ecuador' },
{ name: 'Samantha', email: '[email protected]', age: 30,
country: 'United States' },
{ name: 'Nicole', email: '[email protected]', age: 43,
country: 'Colombia' },
{ name: 'Natasha', email: '[email protected]', age: 54,
country: 'Ecuador' },
{ name: 'Michael', email: '[email protected]', age: 15,
country: 'Colombia' },
{ name: 'Nicolás', email: '[email protected]', age: 43,
country: 'Colombia' }
];
for(var i =0; i < people.length; i++) {
multipleDemo.push(people[i]);
people.splice(people[i], 1000);
console.log(multipleDemo);
console.log(people);
}
Example code: https://plnkr.co/edit/UJfRUs6dAT1NC1EnOvqA?p=preview
I want to leave { name: 'Adam', email: '[email protected]', age: 12, country: 'United States' } in array people. Rest of elements I want to put in array multipleDemo
I want such as FINISH EFFECT:
let multipleDemo =[,
{ name: 'Amalie', email: '[email protected]', age: 12,
country: 'Argentina' },
{ name: 'Estefanía', email: '[email protected]', age: 21,
country: 'Argentina' },
{ name: 'Adrian', email: '[email protected]', age: 21,
country: 'Ecuador' },
{ name: 'Wladimir', email: '[email protected]', age: 30,
country: 'Ecuador' },
{ name: 'Samantha', email: '[email protected]', age: 30,
country: 'United States' },
{ name: 'Nicole', email: '[email protected]', age: 43,
country: 'Colombia' },
{ name: 'Natasha', email: '[email protected]', age: 54,
country: 'Ecuador' },
{ name: 'Michael', email: '[email protected]', age: 15,
country: 'Colombia' },
{ name: 'Nicolás', email: '[email protected]', age: 43,
country: 'Colombia' }];
let people = [
{ name: 'Adam', email: '[email protected]', age: 12,
country: 'United States' }
];
for(var i =1; i < people.length; i++) {in your loop?