P
P
p3trukh1n2019-05-19 17:02:59
JavaScript
p3trukh1n, 2019-05-19 17:02:59

How to get only some elements of an array using destructuring?

An array comes into the function parameter

[(не нужное), (не нужное), (НУЖНОЕ №1), (не нужное), (НУЖНОЕ №2)]

I wrote the function very nicely,
function someFunction([null, null, null, id, null, status]) {
    ...
}

But writes Duplicate parameters are invalid.
How can an array be destructured to get only the 3rd and 5th elements?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-05-19
@p3trukh1n

Instead of unnecessary elements, do not specify anything: Or, you can destructure the array as a regular object:
function someFunction([ ,,, id,, status ]) {
function someFunction({ 3: id, 5: status }) {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question