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 7530031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:47:57+00:00 2026-05-30T04:47:57+00:00

Some outside code is giving me a string value like.. null,402,2912,2909,2910,2913,2911,2914,2915,2388,2389,2390, now i have

  • 0

Some outside code is giving me a string value like..

null,402,2912,2909,2910,2913,2911,2914,2915,2388,2389,2390,

now i have to save this value to the data base but putting 0 in place of null in javascript. Is there any javascript string releated function to do this conversion?

  • 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-05-30T04:47:58+00:00Added an answer on May 30, 2026 at 4:47 am

    You can simply use the replace function over and over again until all instances are replaced, but make sure that all your string will ever contain is the character sequence null or a number (and obviously the delimiting comma):

    var str = "null,402,2912,null"
    var index = str.indexOf("null");
    
    while(index != -1) {
        str = str.replace("null", "0");
        index = str.indexOf("null");
    }
    

    You need to run a for loop because the function String.replace(search, rplc) will replace only the first instance of search with rplc. So we use the indexOf method to check, in each iteration, if the required term exists or not. Another alternative (and in my opinion, a better alternative would be:

    var str = "null,402,2912,null"
    var parts = str.split(",");
    var data = []
    
    for(var i=0; i<parts.length; i++) {
        data[data.length] = parts[i]=="null"?0:parseInt(parts[i]);
    }
    

    Basically, what we are doing is that since you will anyways be converting this to an array of numbers (I presume, and sort of hope), we first split it into individual elements and then inspect each element to see if it is null and make the conversion accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've developed some code that executes a quartz job.At first the code was outside
I'm writing code to download email from various servers, some of which are outside
Some simple code: - (IBAction)Up_Down:(UIStepper *)sender { double value = [sender value]; [NumDayLabel setText:[NSString
I have a project to move some JS code outside of rails into the
I would like to perform checking on the following: VALID LINES; /**/ some code
i have a code like this, but giving error can not access protected member.
I have some code like this: #define FORCE_DEBUG_MODE [[[NSUserDefaults standardUserDefaults] valueForKey:@forceDebugMode] isEqualToString:@1] #if defined
Most people seem to declare functions outside the code block that's using them like
Say you get a file handle from some outside DLL and instantiate a FileStream
Some of my PHP domain objects have properties which should be set from outside

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.