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

151
Views
i want Give values for a nested object from array js

I'm trying to replace the "hi" value with serial values from the array But that didn't work

I'm trying to replace the "hi" value with serial values from the array But that didn't work


    let final = [
      [ 'q0', 'S0' ],
      [ 'q1', 'S0' ],
      [ 'q0', 'S1' ],
      [ 'q2', 'S0' ]
    ]

    let array = m [
      [ 'q1', 'S0' ], 
      [ 'q0', 'S1' ],
      [ 'q1', 'S0' ], 
      [ 'q2', 'S1' ],
      [ 'q1', 'S1' ], 
      [ 'q0', 'S0' ],
      [ 'q1', 'S1' ], 
      [ 'q0', 'S0' ]
    ]

I'm trying to replace the "hi" value with serial values from the array But that didn't work

    var target1 = {};
    arr.forEach((key1) => target1[key1] ="hi" )
        
    var target = {};
    final.forEach((key) => target[key] = target1);
        
    var dict = {
      "states" : final,
      "inputAlphabet" :["0","1"],
      "startState" : final[0],
      "EndStates" : [ 'q2', 'S0' ],
      target
    };
    ```   

{
  "states":
    [["q0","S0"],["q1","S0"],["q0","S1"],["q2","S1"], 
   ["q1","S1"],["q2","S0"] ],
  "inputAlphabet": ["0","1"],
  "startState":["q0","S0"],
  "EndStates":["q2","S0"],
  "target":{
    "q0,S0":{"0":"hi","1":"hi"},
    "q1,S0":{"0":"hi","1":"hi"},
    "q0,S1":{"0":"hi","1":"hi"},
    "q2,S0":{"0":"hi","1":"hi"}
  }
}

i want Give values for a nested object from array js As in the example below

"target":{
  "q0,S0":{"0":array[0],"1":array[1]},
  "q1,S0":{"0":arary[2],"1":array[3]},
  "q0,S1":{"0":array[4],"1":array[5]},
  "q2,S0":{"0":array[6],"1":array[7]}
}

about 4 years ago · Juan Pablo Isaza
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!