I have array in quasar
{1: {…}, 2: {…}, 12: {…}, 13: {…}, 14: {…}, 15: {…}}
1
:
{id: 1, title: 'Supreme Court dubs Manipur', news: 'PTI, New Delhi, JUL 20 2023, 11:23 ISTUPDATED: JUL…isturbing-asks-centre-to-take-action-1238849.html', created_by: 10000001, updated_by: null, …}
2
:
{id: 2, title: 'test for reverse', news: 'reverse test In the above program, the user is pro…d to enter a string. That string is passed to the', created_by: 10000001, updated_by: 10000001, …}
12
:
{id: 12, title: 'cc', news: 'cc', created_by: 10000001, updated_by: null, …}
13
:
{id: 13, title: 'aa', news: 'aa', created_by: 10000001, updated_by: null, …}
14
:
{id: 14, title: 'jj', news: 'jj', created_by: 10000001, updated_by: null, …}
15
:
{id: 15, title: 'mm', news: 'h', created_by: 10000001, updated_by: null, …}
[[Prototype]]
:
How to remove to complete row with key 12?
I have tried
let id = 12
master.news.splice(id, 1)
But getting error: Uncaught TypeError: master.news.splice is not a function
2
Answers
The
master.news
looks like an object with indexes as keys, you could use thedelete
operator to remove that property :JavaScript
splice()
method works on an array but as per the data structure,master.news
is an object with numbered keys (e.g., 1, 2, 12, etc.). Hence, you can not perform splice directly on it.To make it work you have to use
delete
operator.You can try this :