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;
}
Expected Result:
all user should be like this
[{ "username":"John", "userage":30 },{ "username":"Raj", "userage":28 }]