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

223
Views
Updating an Array that's present inside an Object

I'm trying to update an array (Array name is "Variables" please refer the attached screenshot) which presents inside an Object, so I want to update that array if there is word called "placeholder" in alertMessage(it's a different property presents in the same Object)

I'd appreciate any help on how to update this array in question, I tried using pop method but it didn't go as planned and I've attached screenshots of the Objects for reference

enter image description here

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You can retrieve the string placeholder like this data['alertMessage']['en_US']['all'] and then use a conditional statement to make changes to the array inside the data object.

let data = {
  alertOne: '',
  alertTwo: '',
  alertMessage: {
    en_US: {all: 'placeholder'}
  },
  variables: [
     {id: 0, uuid: '123'},
     {id: 1, uuid: '223'},
     {id: 2, uuid: '323'}
  ]
}

let all = data['alertMessage']['en_US']['all']

// if condition is met add a new object to the array
if(all === 'placeholder'){
  data.variables = [...data.variables, {id: 3, uuid: '423'}] 
}

console.log(data)

about 4 years ago · Santiago Gelvez 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!