<script>
var bookList = [
{name:"什么是批判",author:"福柯"},
{name:"飞鸟集",author:"泰戈尔"}
];
//增加操作
bookList.push({name:"城堡",author:"卡夫卡"});
//查询操作
for (var i = 0; i < bookList.length; i++) {
var obj = bookList[i];
if (obj.name == "飞鸟集")
{
console.log(obj);
break;
}
}
//修改操作
for (var i = 0; i < bookList.length; i++) {
var obj = bookList[i];
if (obj.name == "飞鸟集")
{
obj.author = "泰戈尔-戈尔泰"
}
}
//删除操作
for (var i = 0; i < bookList.length; i++) {
var obj = bookList[i];
if (obj.name == "飞鸟集")
{
//删除该对象
bookList.splice(i, 1);
}
}
console.log(bookList);
</script>
网友评论