wasantha
wasantha

Reputation: 49

how to remove keys of object inside with another object

i need to remove keys of the objects inside with another object using typescript.

let before = {
  '0': {
    'title':'title 1',
    'time':'12.30pm',
  },

  '1': {
    'title':'title 2',
    'time':'12.30pm',
  },

  '2': {
    'title':'title 3',
    'time':'12.30pm',
  },
}

expected results,

let after = [
  { 
    'title':'title 1',
    'time':'12.30pm',
  },

  {
    'title':'title 2',
    'time':'12.30pm',
  },

  {
    'title':'title 3',
    'time':'12.30pm',
  }
]

Upvotes: 1

Views: 64

Answers (2)

Naga Sai A
Naga Sai A

Reputation: 10975

To achieve expected result, use below option of using Object.entries and map

  1. Object entries returns array of object's key value pair
  2. Using map return value

let before = {
  '0': {
    'title':'title 1',
    'time':'12.30pm',
  },

  '1': {
    'title':'title 2',
    'time':'12.30pm',
  },

  '2': {
    'title':'title 3',
    'time':'12.30pm',
  },
}

console.log(Object.entries(before).map(v => v[1]))

Upvotes: 1

guijob
guijob

Reputation: 4488

Just use Object.values(before)

let before={0:{title:"title 1",time:"12.30pm"},1:{title:"title 2",time:"12.30pm"},2:{title:"title 3",time:"12.30pm"}};


console.log(Object.values(before));

Upvotes: 6

Related Questions