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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:07:51+00:00 2026-05-25T21:07:51+00:00

I have a javascript object that goes like this: var obj = {data: [

  • 0

I have a javascript object that goes like this:

var obj = {"data":
 [
  {"name":"Alan","height":1.71,"weight":66},
  {"name":"Ben","height":1.82,"weight":90},
  {"name":"Chris","height":1.63,"weight":71}
 ]
 ,"school":"Dover Secondary"
}

How do I create a new field called BMI using weight/(height)^2 such that the new object becomes:

var new_obj = {"data":
 [
  {"name":"Alan","height":1.71,"weight":66,"BMI":22.6},
  {"name":"Ben","height":1.82,"weight":90,"BMI":27.2},
  {"name":"Chris","height":1.63,"weight":71,"BMI":26.7}
 ]
 ,"school":"Dover Secondary"
}
  • 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-25T21:07:51+00:00Added an answer on May 25, 2026 at 9:07 pm
    var persons = obj.data;
    var new_obj = {data: [], school: obj.school};
    for(var i=0; i<persons.length; i++){
        var person = persons[i];
        new_obj.data.push({
            name: person.name,
            height: person.height,
            weight: person.weight,
            BMI: Math.round(person.weight / Math.pow(person.height, 2)*10)/10;
        });
        /* Use the next line if you don't want to create a new object,
           but extend the current object:*/
        //persons.BMI = Math.round(person.weight / Math.pow(person.height, 2)*10)/10;
    }
    

    After new_obj is initialised, a loop walks through array obj.data. The BMI is calculated, and added along with a copy of all properties to new_obj. If you don’t have to copy the object, have a look at the commented part of the code.

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

Sidebar

Related Questions

I have a javascript object that looks somthing like this: var obj = {
I have a javascript that does this (http is your XMLHttpRequest object) var r
I have a Javascript object that (very simplified) looks like this if('undefined' !== typeof(listCtrls)){
I'm creating my own JavaScript Array-like object and I have methods that call closures.
I have an object I created in JavaScript. Let's say it looks like this:
I have a JavaScript object that I'd like to add some properties to, but
I have an javascript object that contains a select list. I'd like to loop
I have a JavaScript object that looks like the following: venue = function(map, dataSet)
I have a javascript hash (object?) we will call settings_hash that basically looks like
I have a Javascript object that requires 2 calls out to an external server

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.