S
S
shynga2020-04-20 12:16:07
JavaScript
shynga, 2020-04-20 12:16:07

How to sort the new array?

Good afternoon!
Can you tell me how to add a new array element to an array and sort all the elements of the new array?

It is possible both on ES5, ES6, and on jQuery.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tigran Abrahamyan, 2020-04-20
@shynga

So what?

const arr = [4, 63, 3, 87];

console.log(arr.sort((a, b) => a - b));

arr.push(2);

console.log(arr.sort((a, b) => a - b));

M
McBernar, 2020-04-20
@McBernar

How to sort? On what basis?
Briefly, then

arr.push(elem)
arr.sort()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question