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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:06:29+00:00 2026-06-06T17:06:29+00:00

I have a working JavaScript code below which dynamically creates JSON object using JSON.parse

  • 0

I have a working JavaScript code below which dynamically creates JSON object using JSON.parse method. Is there a shorter way to do this?

var a = '"hi"'; 
var obj = '{' + a + ':' + '"abc"' + '}';
console.log(JSON.parse(obj)); // outputs: OBJECT: {"hi":"abc"} 

something simplier like…

var a='hi';
console.log({a:"abc"}); // but outputs: OBJECT: {a:"abc"}
  • 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-06T17:06:31+00:00Added an answer on June 6, 2026 at 5:06 pm

    You can use square brackets to access a property whose name you have as a string:

    var a = "hi";
    var obj = {}; //obj is an object literal
    obj[a] = "abc"; //Set the 'hi' property of obj
    

    Note that JSON is just a data format. It is not JavaScript. You want a JavaScript object literal, not JSON.

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

Sidebar

Related Questions

Hi Javascript gurus, I have this Javascript code which is working fine on Firefox
I have the below code which prints out the date which is 10 working
I have the working code pasted below which has a function called FormatStatus() as
I am working on a javascript project which involves parsing xml data. I have
I have this code http://jsfiddle.net/xNHKP/6/ (not working in the fiddle for some reason which
Possible Duplicate: JavaScript: string contains In the below code I have to check whether
I have this HTML code, which is invoking my javascript code. The code is
So I have been working with javascript for a website I am designing, shocker
I have been working on facebook application and you know on facebook native javascript
I have this function working <script type=text/javascript> $(window).scroll(function() { if ($(window).scrollTop() == $(document).height() -

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.