Telegram Group & Telegram Channel
3 способа преобразования массива в объект

Приветствую товарищи! Довольно часто по разным причинам нам требуется трансформировать данные в какой-либо формат, например для работы с какой-нибудь библиотекой или апихой. В этом посте описаны 3 способа с помощью которых можно массив трансформировать в объект.

const arr = ['frontend', 'backend', 'qa'];

// 1 способ - метод assign
const obj = Object.assign({}, arr);

// 2 способ - spread оператор
const obj = {...arr};

// 3 способ - метод reduce
const obj = arr.reduce((res, key, index) => {
res[index] = key;
return res;
}, {})

#js #features



tg-me.com/projavascript/155
Create:
Last Update:

3 способа преобразования массива в объект

Приветствую товарищи! Довольно часто по разным причинам нам требуется трансформировать данные в какой-либо формат, например для работы с какой-нибудь библиотекой или апихой. В этом посте описаны 3 способа с помощью которых можно массив трансформировать в объект.

const arr = ['frontend', 'backend', 'qa'];

// 1 способ - метод assign
const obj = Object.assign({}, arr);

// 2 способ - spread оператор
const obj = {...arr};

// 3 способ - метод reduce
const obj = arr.reduce((res, key, index) => {
res[index] = key;
return res;
}, {})

#js #features

BY Javascript Pro


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/projavascript/155

View MORE
Open in Telegram


Javascript Pro Telegram | DID YOU KNOW?

Date: |

Telegram is riding high, adding tens of million of users this year. Now the bill is coming due.Telegram is one of the few significant social-media challengers to Facebook Inc., FB -1.90% on a trajectory toward one billion users active each month by the end of 2022, up from roughly 550 million today.

How Does Bitcoin Mining Work?

Bitcoin mining is the process of adding new transactions to the Bitcoin blockchain. It’s a tough job. People who choose to mine Bitcoin use a process called proof of work, deploying computers in a race to solve mathematical puzzles that verify transactions.To entice miners to keep racing to solve the puzzles and support the overall system, the Bitcoin code rewards miners with new Bitcoins. “This is how new coins are created” and new transactions are added to the blockchain, says Okoro.

Javascript Pro from es


Telegram Javascript Pro
FROM USA