How can i add fields inside empty array?

Good morning guys

I have to create a new JSON object array using the user array but when I do this getting the below error.
could someone help me here? or help me to understand the mistake?

var users = [{ "name":"John", "age":30, "car":"fiat" },{ "name":"Raj", "age":28, "car":"hundai" }];

var allUser =[]

for (var i = 0; i < users.length; i++) {
  test(i, users[i])
}
console.log(allUser)

function test(i, user) {
  console.log(i)
  <!-- allUser.push({"username":user.name}); -->

  allUser[i].username = user.name;
  //allUser[i].userage = user.age;
  //allUser[i].usercar = user.car;
}

enter image description here

Expected Result:

all user should be like this

[{ "username":"John", "userage":30 },{ "username":"Raj", "userage":28 }]

75 thoughts on “How can i add fields inside empty array?”

  1. therapie cognitivo comportementale st-jerome pharmacie en ligne italienne , therapies esseniennes therapies breves angers , Mobic pharmacie Canada, Acheter Mobic 15 mg pas cher. Mobic pharmacie Canada Mobic pas cher [url=https://votre12comp.asso-web.com/#]Mobic livraison Canada[/url] therapie de couple streaming vf Acheter Propranolol 40 mg pas cher, Propranolol livraison QuГ©bec. Propranolol sans ordonnance QuГ©bec Propranolol pas cher [url=https://belgique48hand.asso-web.com/#]Propranolol livraison QuГ©bec[/url] , pharmacie odyssee aix en provence therapies epilepsy , pharmacie kremlin bicetre. ouverture pharmacie argenteuil Kamagra livraison Canada, Kamagra livraison Canada. Kamagra pharmacie Canada Kamagra pas cher [url=https://docgosour.asso-web.com/#]Kamagra livraison Canada, Kamagra pas cher[/url] , pharmacie montaigne brest medicaments contenant des sulfites, therapie cognitivo comportementale wikipedia therapie cognitivo comportementale chalon sur saone . medicaments wala, pharmacie auchan leers pharmacie gory bourges pharmacie leclerc lamballe .

    Reply

Leave a Comment