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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:53:44+00:00 2026-06-05T23:53:44+00:00

I have created an empty json object having an array itemlist(which further contains itemid

  • 0

I have created an empty json object having an array itemlist(which further contains itemid and title of an item) by this:

var jsonObj = {};
jsonObj.itemlist=[];
jsonObj.itemlist.push({});

Firstly, have i done the declaration correctly?

Secondly, the title and itemid are generated dynamically so i need to add them to the itemlist array. I tried this but it keeps only one array element:

jsonObj.itemlist['title']=gentitle;
jsonObj.itemlist['itemid']=genitemid;

How can i add multiple elements (not all at once) if i have an empty array of itemlists?

Also, i also need to remove a particular array element based on the title of the element. How can that be done? I think the splice and delete function can be used for this, but how can i find the index of that element?

  • 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-05T23:53:45+00:00Added an answer on June 5, 2026 at 11:53 pm

    since you already pushed a empty object into the array, you need to modify that object:

    jsonObj.itemlist[0]['title']=gentitle;
    jsonObj.itemlist[0]['itemid']=genitemid;
    

    To add more objects, you can do the same thing: push in an empty object, then modify that object. Or, you can create an object, modify it, then push it into the list.

    var new_obj = {'title':gentitle, 'itemid':genitemid};
    jsonObj.itemlist.push( new_obj );
    

    To delete objects with certain attribute value:

    for (var i = jsonObj.itemlist.length-1; i >= 0; i--)
        if(jsonObj.itemlist[i]['title'] == "to-be-removed")
            jsonObj.itemlist.splice(i,1);
    

    Note that you need to go backward, otherwise the splice will mess up the array indexes

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

Sidebar

Related Questions

I have an array that gets created from JSON. The array looks like this:
I have a JSON array like this [{Email:someone@some.com,Name:ACO,Groups:[MOD_SW,MOD_PI,MOD_GE],Id:63,Url:aco}, {Email:someone@some.com,Name:Agpo,Groups:[MOD_PI],Id:22,Url:agpo}, {Email:someone@some.com,Name:Akatherm,Groups:[MOD_SW],Id:64,Url:akatherm}, {Email:someone@some.com,Name:Albrand,Groups:[MOD_PI,MOD_GE],Id:23,Url:albrand}] I want to
I am building an Day View calendar app. I have already created the empty
For a new project I have created a local folder tree with empty Visual
I have a DbContext that is empty. Mappings are created dynamically and the DbContext
I have created a bar chart which is a improvement of bar graph on
i have a script that calls a php file and gets an JSON object
python manage.py dumpdata modelName > file.json . created an empty database for a user
I have created a simple Xcode 4.2 project with a empty view controller. I
I am having a JSON object var jsonString =[ { key: Monday, June 18,

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.