Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
How can I update some array entries to have multiple values?

I have an array as such:

   arr = {
      name: 1,
      address: 1,
      phone: 2,
      email: 5,
   };

I want to be able to add further information to this array, eg:

       arr = {
          name: 1 true,
          address: 1 false,
          phone: 2 true,
          email: 5 true,
       };

I've tried a few different things like:

arr.email[2] = true;

With no results (or errors).

Is there a way to do this? Or a better way of handling this issue?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

I'm not entirely certain what you're going for here since you mention wanting an array ([]) but what you've shown in your question is an object ({}), but if I'm reading right you can accomplish this with an object where each key holds an array of values. That would look like:

const obj = {
  name: [1],
  address: [1],
  phone: [2],
  email: [5],
};

obj.email.push(true);
obj.email.push("whatever");

console.log(obj)
console.log(obj.email[1])
console.log(obj.email[2])

So obj is an object, but name, address, phone, and email are all arrays which you can extend as needed with array methods.

about 4 years ago · Juan Pablo Isaza Report

0

Original data structure doesn't allow you to add data the way you want. So you have to create the object with needed data structure at first. After this the original data should be moved to the new object and only after this you can add some new data.

     newObj.name.push(origObj.name,true,"something1","something2");
     newObj.address.push(origObj.address,false);
     newObj.phone.push(origObj.phone,true);
     newObj.email.push(origObj.email,true);

output

{
"name":[1,true,"something1","something2"],
"address":[1,false],
"phone":[2,true],
"email":[5,true]
}

original object

    var origObj = {
        name: 1,
        address: 1,
        phone: 2,
        email: 5
    };

new object

    var newObj = {
        name: [],
        address: [],
        phone:[],
        email: []
    };
about 4 years ago · Juan Pablo Isaza Report

0

You would need to assign a variable to your array and call a function...that way, each element could be classified (boolean, string, integer, etc.) For example,

const fruit = ['banana', 'apple', 'pear'];
console.log(fruit);   
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!