1

I have array which values look like this in image

enter image description here

I need to convert in one arry like { "1vwxnrjq", "dasdada", "adsdadsada"} like this

console.log(items);
this.ids = items.id;
console.log(this.ids);

I am doing like this but its showing undefined

2 Answers 2

4

the easiest solution will be to just use the map function

console.log(items.map(r=>r.id))

const items=[{id:1},{id:2},{id:3}];
console.log(items.map(r=>r.id));

Sign up to request clarification or add additional context in comments.

Comments

3

You can do it like follows, first convert all into lowercase and then pick the length of substring you want. From below you can replace 9 with a variable value to get the length of substring you want.

temp = arr.map((item)=>{
  return item.id.toLowerCase().substr(0,9);
})

Working snippet:

arr = [{id:"dafSDFdDfdafd"},{id:"adfdDFAsssd"},{id:"12adfdDFAsssd"}];

temp = arr.map((item)=>{
  return item.id.toLowerCase().substr(0,9);
})

console.log(temp);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.