Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7916205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:43:21+00:00 2026-06-03T14:43:21+00:00

Simple javascript question: I have an array (50=50; 49=49; 143=143; 4005=4005; … ) which

  • 0

Simple javascript question:

I have an array (50=50; 49=49; 143=143; 4005=4005; … )
which i want to turn into (50; 49; 143; 4005; …).

The name will always be the same as the value, in the name=value pair.
It will always be a number (but of various lengths).

I just cant get my head around it using .split

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:43:22+00:00Added an answer on June 3, 2026 at 2:43 pm

    Assuming that you mean you have an array like this:

    var arr = ['50=50;','49=49;','143=143;','4005=4005;'];
    

    Then, you may employ split like this:

    var newArr = [], ii;
    for (ii = 0; ii < arr.length; ii += 1) {
        newArr.push(parseInt(arr[ii].split('=')[0], 10));
    }
    

    This will result in newArr being equal to this:

    var newArr = [50, 49, 143, 4005];
    

    The way split works is it divides a string up into an array based on a delimiter string. In this example, we’ve used '=' as the delimiter, so we end up with arrays like this:

    ['50', '50;']
    ['49', '49;']
    // etc.
    

    Then, index into the first element and pass it to parseInt to produce a number, and push onto a new array with just number elements.

    Here’s a working example.

    Addendum

    If you aren’t starting with an actual JavaScript array, but a string that you’d like to turn into an array, then add this step before the previous ones to get yourself the original array:

    var str = '(50=50; 49=49; 143=143; 4005=4005;)';
    var arr = str.replace(/\(|\)|;/g, '').split(' ');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple question concerning Javascript. I am trying to print in a
Simple question... How am I going to reproduce Javascript bugs if I don't have
I have a simple JavaScript Array object containing a few numbers. [267, 306, 108]
I have a very simple JavaScript array that may or may not contain duplicates.
I have a simple javascript question in the HTML page. In my case, the
Possible Duplicate: JavaScript arrays braces vs brackets I have a simple question that I
Here comes a simple question, for all those who know javascript. I made an
I have a simple JavaScript file that has three jQuery $document.ready functions. All three
I have a simple JavaScript game that sends a score to PHP by adding
I have an array: myarr = []; I'm filling it with some values: myarray['name']

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.