A
A
alex4answ2020-11-24 17:16:52
typescript
alex4answ, 2020-11-24 17:16:52

How to remove an array element returned by a function?

Good afternoon, there is a function that returns a promise with an array of numbers.

How to remove an element from the result in an async function without additional variables?

async function a(): Promise<number[]> {
  return [1, 2, 3];
}

async function b(): Promise<void> {
  const tmp = await a();
  const result = tmp.shift();
  // что-то с result
}


I'm sure there is some simple solution that flew out of my head

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-11-24
@alex4answ

async function a(): Promise<number[]> {
  return [1, 2, 3];
}

async function b(): Promise<void> {
  const [shift, ...result] = await a();
  // что-то с result
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question