Link to home
Start Free TrialLog in
Avatar of juan field
juan field

asked on

how can i turn the array into an object

// This is what i have so far:
// my output is supposed to be this :

//{
  //Queen : 'Beyonce'
//}








function transformFirstAndLast(array) {
  var result = {};
  result = array[0] + " : " + array.pop();
  for(var key in result){
    key = array[0];
  }
  return result;
}

console.log(transformFirstAndLast(['Queen', 'Elizabeth', 'Of Hearts', 'Beyonce']));
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of juan field
juan field

ASKER

how about like this :

//{
  //Queen : 'Beyonce'
//}

// is it possible?
//ok, got it :


function transform(myArray) {
  var result = {};
    result[myArray[0] ] = myArray.pop();
  return result;
}

console.log(transform(['Queen', 'Elizabeth', 'Of Hearts', 'Beyonce']));



// thank you zephyr_hex (Megan)
thank you zephyr_hex (Megan)