Javascript Nativescript简单删除函数

Javascript Nativescript简单删除函数,javascript,xml,nativescript,typeerror,Javascript,Xml,Nativescript,Typeerror,好的,所以我遇到的问题是,如何将当前索引与页面[]的最后一个索引交换,并将其弹出 下面是我的fileSystemService.js中的一段代码: fileSystemService.prototype.deletePage = function (notePage) { //Saving pages to the file system var pages = this.getPages(); //Checking if the page already exists so that it

好的,所以我遇到的问题是,如何将当前索引与页面[]的最后一个索引交换,并将其弹出

下面是我的fileSystemService.js中的一段代码:

fileSystemService.prototype.deletePage = function (notePage) { //Saving pages to the file system
var pages = this.getPages();

//Checking if the page already exists so that it updates it
var index = pages.findIndex(function (element) {
    return element.id === notePage.id;
});
if (index !== -1) { //if the page is found

        notePage.id[index] = pages.id[pages.length-1]
        notePage.title[index] = pages.title[pages.length-1]
        notePage.n[index] = pages.n[pages.length-1]
        notePage.image[index] =pages.image[pages.length-1]
    pages.pop();
}

var json = JSON.stringify(pages); //Converting objs to json and save to the file system
this.file.writeTextSync(json);
})

没有什么太复杂的,下面是测试链接:


好的,我找到了解决我错误的方法

pages[index] = pages[pages.length-1]
pages.pop();
由于数组“pages”中没有“id”这样的东西,因此标记了一个错误 希望有人觉得这有用;v
凌晨3点解决了它

哪一行代码被标记为错误?啊,错误是notePage.id[index]=pages.id[pages.length-1]
pages[index] = pages[pages.length-1]
pages.pop();