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

211
Views
How to convert Array of string to List of string in react js

How to add a string item to the list in react js. sample Code:

const value1="Book";
const value2="Pen";
const value3="Note";

const arrayValue=[];
arrayValue.push(value1);
arrayValue.push(value2);
arrayValue.push(value3);
console.log(arrayValue);

Output is : ["Book","Pen","Note"];
expected output is : object:{[0]."Book",[1]."Pen",[2]."Note"}

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

0

You can make an object instead of array like this

const arrayValue={};
arrayValue['1'] = value1;
// Same for the other values
about 4 years ago · Juan Pablo Isaza Report

0

const value1="Book";
const value2="Pen";
const value3="Note";

const arrayValue=[];
arrayValue.push(value1);
arrayValue.push(value2);
arrayValue.push(value3);
console.log(arrayValue);
const newObj = {}
for (let i = 0; i < arrayValue.length; i++) {
  newObj[i] = arrayValue[i]
}
console.log(newObj)

This is what is logged

["Book", "Pen", "Note"]
[object Object] {
  0: "Book",
  1: "Pen",
  2: "Note"
}
const value2="Pen";
const value3="Note";

const arrayValue=[];
arrayValue.push(value1);
arrayValue.push(value2);
arrayValue.push(value3);
console.log(arrayValue);
const newObj = {}
for (let i = 0; i < arrayValue.length; i++) {
  let string = `[${i.toString()}]`
  newObj[string] = arrayValue[i]
}
console.log(newObj)

This is Logged

["Book", "Pen", "Note"]
[object Object] {
  [0]: "Book",
  [1]: "Pen",
  [2]: "Note"
}
about 4 years ago · Juan Pablo Isaza Report

0

var obj = {}
for (var i in arrayValue){
    obj[i] = arrayValue[i];
}

console.log(obj)
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!