is it possible simplify .map's return statement? I want to add key for each element in the array, and transform arr to array of object. thanks!
let arr = ['c:/a.txt', 'b:/c.txt', 'd:/e.txt'];
let arrObj = arr.map((file) => return {path: file});
is it possible simplify .map's return statement? I want to add key for each element in the array, and transform arr to array of object. thanks!
let arr = ['c:/a.txt', 'b:/c.txt', 'd:/e.txt'];
let arrObj = arr.map((file) => return {path: file});
You could use a short hand property.
let arr = ['c:/a.txt', 'b:/c.txt', 'd:/e.txt'],
arrObj = arr.map(path => ({ path }));
console.log(arrObj);