JavaScript Array to Object: изменение элементов массива в свойство и значение объекта
0принят
Ну вот
var arr=["Orange","glass","hat","juicy","green"]function firstAndLast(arr){return{[arr[0]]: arr[arr.length -1]}}
результат
{Orange:'green'}
0
На самом деле это довольно просто
var array =["Orange","glass","hat","juicy","green"];// take the first elem and map it to the last element// the index of the last element being array.length - 1var res ={[array[0]]: array[array.length -1]};
console.log(res);
0
var array =["Orange","glass","hat","juicy","green"];var myelem ={[array[0]]: array[array.length-1]};
console.log(myelem);
var arr=["Orange","glass","hat","juicy","green"]function firstAndLast(arr){return{[arr[0]]: arr[arr.length -1]}}
результат
{Orange:'green'}
0
На самом деле это довольно просто
var array =["Orange","glass","hat","juicy","green"];// take the first elem and map it to the last element// the index of the last element being array.length - 1var res ={[array[0]]: array[array.length -1]};
console.log(res);
0
var array =["Orange","glass","hat","juicy","green"];var myelem ={[array[0]]: array[array.length-1]};
console.log(myelem);