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

  • Home
  • SEARCH
  • 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 8819427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:21:21+00:00 2026-06-14T05:21:21+00:00

I am trying to dynamically add categories to JavaScript object from a string. But

  • 0

I am trying to dynamically add categories to JavaScript object from a string. But the problem is that commas inside this string are not recognized as separate items.

So I have this:

var prices = json_graph['offer_prices'].join(','); // that returns for example '2,3,4,5'

Then I want to use this like so:

xAxis: {
  categories: [prices]
}

The problem is, that this is recognized as a single item. How can I split this string by commas and add it under categories?

Thanks for your help!

  • 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-14T05:21:22+00:00Added an answer on June 14, 2026 at 5:21 am

    From the fact you’re using join on it, I’d say the offer_prices property is an array. So there’s no need to turn it into a string (but see below, if you have a reason for doing that you haven’t shown):

    xAxis: {
        categories: json_graph['offer_prices']
    }
    

    Or if you want to make a copy of it for some reason rather than using the original:

    xAxis: {
        categories: json_graph['offer_prices'].slice(0) // slice(0) = shallow copy
    }
    

    If you have a reason for creating the prices string and really do want to use it for this, you can do that by splitting it apart using the comma as a delimiter, with split:

    xAxis: {
        categories: prices.split(',')
    }
    

    Side note: You’ve written json_graph['offer_prices'] and so that’s what I’ve used above, but if you’re literally using that in your code, you can just write json_graph.offer_prices instead if you want, barring some reason you need not to (you might need the string with some tool or something you’re using, I wouldn’t know).

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

Sidebar

Related Questions

I am trying to dynamically add and remove JSON elements from json object. But
New to javascript and jQuery, but I'm trying to dynamically add buttons and then
I'm trying to dynamically add some paths to a Grid, but this generates an
Im trying to add a div tag dynamically with some data attributes but the
we are trying to add ColumnDefinition to a Grid in WPF dynamically from code
I am trying and failing to add datepicker to inputs that are created dynamically.
I have a page that I am trying to dynamically add some links to.
I have a site with three tabs that I'm trying to dynamically add mouseover/mouseout
This is related to . I'm trying to dynamically add the maven-ant-tasks jars with
I'm trying to dynamically add a css stylesheet rule using javascript, something like example

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.