СО
Size: a a a
СО
РК
РК
РК
class DB {
constructor() {
this.db = [
{ id: 0, name: 'Name' },
{ id: 1, name: 'Name2' },
{ id: 2, name: 'Name3' },
]
}
deleteInstanseById(idx) {
this.db = this.db.filter((e) => e.id != idx)
}
}
db = new DB()
db.deleteInstanseById(1)
console.log(db.db)
//измененный массив
Д
class DB {
constructor() {
this.db = [
{ id: 0, name: 'Name' },
{ id: 1, name: 'Name2' },
{ id: 2, name: 'Name3' },
]
}
deleteInstanseById(idx) {
this.db = this.db.filter((e) => e.id != idx)
}
}
db = new DB()
db.deleteInstanseById(1)
console.log(db.db)
//измененный массив
EP
let obje = [
{ id: 0, name: 'Name' },
{ id: 1, name: 'Name2' },
{ id: 2, name: 'Name3' },
]
function deleteInstanseById(idx, o) {
o = o.filter(function (e) {
return e.id != idx
})
}
deleteInstanseById(1, obje)Здравствуйте, почему функция не удаляет элемент из массива?
console.log(obje) // тот же массив
let obje = [
{ id: 0, name: 'Name' },
{ id: 1, name: 'Name2' },
{ id: 2, name: 'Name3' },
]
Object.prototype.deleteInstanseById = function (idx){
const arrIndex = this.findIndex((el)=>el.id === idx)
arrIndex !== -1 && this.splice(arrIndex, 1);
}
obje.deleteInstanseById(1)
console.log(obje) // тот же массив без элемента
EP
РК
createInstance(name) {
return { id: last(this.db).id + 1, name: name }
}
addInstance(name) {
this.db.push(this.createInstance(name))
}
Я базу данных проектируюБО
СО
createInstance(name) {
return { id: last(this.db).id + 1, name: name }
}
addInstance(name) {
this.db.push(this.createInstance(name))
}
Я базу данных проектируюРК
РК
СО
РК
М