-2

I have a jQuery array ["3434", "3433"]

And I would like to make it like [3434, 3433]

1
  • 3
    ["3434", "3433"].map(Number) Commented Mar 20, 2018 at 8:05

1 Answer 1

5

No need for jQuery. Supposing you're sure they're all numbers (that is, we're not checking for errors), you can map them with Number, which converts them from string to numbers.

["3434", "3433"].map(Number);

Considering that Number returns NaN in case of error, you may then want to filter the result to remove undesired elements.

let nums = ["3434", "3433", "foo"].map(Number).filter(n => !isNaN(n));
console.log(nums);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.