Похожие чаты

Hmm. Guys, say you have {x, y} and you have an

array with [1, 2], is there an elegant way to merge it so it's just {x:1, y:2}?

11 ответов

16 просмотров

{x: 'x', y: 'y'} you mean ?

You want to use the keys of an object to fill in the array values? 🤔

let obj = {x: '', y: ''} let arr = [1, 2] Object.keys(obj).reduce((newObj, item, i) => { newObj[item] = arr[i] return newObj }, {})

J-: Vaccinated 🇨🇦 Автор вопроса
Misan
You want to use the keys of an object to fill in t...

I want to fill in X amount of keys depending on how many elements are in the array

J-: Vaccinated 🇨🇦 Автор вопроса
Danial Dezfouli
let obj = {x: '', y: ''} let arr = [1, 2] Object....

I noticed it crashes after changing the object size, so I made it arr[i] || obj[item] and it's working good 👌

const [x, y] = [1, 2]; const obj = {x, y};

J-: Vaccinated 🇨🇦 Автор вопроса
Banana
const [x, y] = [1, 2]; const obj = {x, y};

And if they're not exactly the same size? For example {x, y, z:3} and [1, 2] for {x:1, y:2, z:3}?

J-: Vaccinated 🇨🇦 Автор вопроса
Banana
I'm not entirely sure what you're trying to do.

Here's a few examples. {x} • [1, 2] = {x:1} {x, y} • [1, 2] = {x:1, y:2} {x, y, z} • [1, 2] = {x:1, y:2, z}

J-: Vaccinated 🇨🇦 Автор вопроса
Danial Dezfouli
let obj = {x: '', y: ''} let arr = [1, 2] Object....

Just pop the values in one by one until you can't fit anymore into either one or until it's done lol but the solution here worked

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта