juan field
asked on
how can i make the array into an object?
// FROM THIS :
var classList = ["Joe", "Jack", "John", "Fred", "Frank", "Barry", "Larry", "Mary",
"Harry", "Farrell", "Susan", "Monica", "Keira", "Caroline", "Harriet", "Erica",
"Luann", "Cheryl", "Beth", "Rupa", "Linda", "Allison", "Nancy", "Dora"];
// TO THIS :
var classListWithAges = [{"name":"Joe","age":11},{ "name":"Ja ck","age": 10},
{"name":"John","age":11},{ "name":"Fr ed","age": 11},{"name ":"Frank", "age":11},
{"name":"Barry","age":11}, {"name":"L arry","age ":11},{"na me":"Mary" ,"age":11} ,
{"name":"Harry","age":11}, {"name":"F arrell","a ge":10},{" name":"Sus an","age": 10},
{"name":"Monica","age":11} ,{"name":" Keira","ag e":10},{"n ame":"Caro line","age ":10},
{"name":"Harriet","age":11 },{"name": "Erica","a ge":11},{" name":"Lua nn","age": 10},
{"name":"Cheryl","age":11} ,{"name":" Beth","age ":10},{"na me":"Rupa" ,"age":11} ,
{"name":"Linda","age":10}, {"name":"A llison","a ge":10},{" name":"Nan cy","age": 10},
{"name":"Dora","age":10}]
// THIS IS WHAT I HAVE SO FAR :
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function decorateClassListWithAges( arr) {
var result = [];
var groups = {
name: name,
age: getRandomIntInclusive(10, 11)
};
for(var i = 0; i < arr.length; i++){
groups.name = arr[i];
}
//return result;
return result.push(groups);
}
console.log(decorateClassL istWithAge s(classLis t));
var classList = ["Joe", "Jack", "John", "Fred", "Frank", "Barry", "Larry", "Mary",
"Harry", "Farrell", "Susan", "Monica", "Keira", "Caroline", "Harriet", "Erica",
"Luann", "Cheryl", "Beth", "Rupa", "Linda", "Allison", "Nancy", "Dora"];
// TO THIS :
var classListWithAges = [{"name":"Joe","age":11},{
{"name":"John","age":11},{
{"name":"Barry","age":11},
{"name":"Harry","age":11},
{"name":"Monica","age":11}
{"name":"Harriet","age":11
{"name":"Cheryl","age":11}
{"name":"Linda","age":10},
{"name":"Dora","age":10}]
// THIS IS WHAT I HAVE SO FAR :
function getRandomIntInclusive(min,
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function decorateClassListWithAges(
var result = [];
var groups = {
name: name,
age: getRandomIntInclusive(10, 11)
};
for(var i = 0; i < arr.length; i++){
groups.name = arr[i];
}
//return result;
return result.push(groups);
}
console.log(decorateClassL
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
luv it luv it !!! thank you . At the beginning i wanted to push in the result , but on terminal i got "not a function" ... then i wanted to make a curly brace var , and then add into the array .. i dont remember what else i did ... but i spent a lot of time trying to make it happen... when a lot of hours passed that is when i decided to ask experts. Thank you again.
You are welcome.
Open in new window