我的函数不会返回要保存在数组中的对象
my function wont return the object to be saved in the array
我无法获得返回对象并保存在数组中的代码,第一个函数是保存数组中的歌曲,第二个函数是搜索已经保存在数组中的歌曲
function save() {
//loop to keep adding songs within the array
var addSong = //create the object inside the function
{
title: document.number.title.value,
artist: document.number.artist.value,
col: document.number.col.value,
dur: document.number.dur.value
};
//output the song title of the saved song
document.number.saved.value = addSong.title;
return addSong;
}
//----------------------------------------------------------
var sTitle = document.searchSong.searchTitle.value; // assigning the search box to 'sTitle'
var library = new Array() //array to store each song
var song = addSong.title;
//-----------------------------------------------------------
//function to search for a song saved in the music() array
function search() {
//if statement to compare the inputs and see if the song is in the
library
if (sTitle == song) {
//if the song title is there then it is output
document.searchSong.result.value = song;
} else {
//if not then 'no song' is output instead
document.searchSong.result.value = "no song";
}
}
您需要调用函数save()并将其结果分配给名为addSong的变量。
var addSong = save();
var song = addSong.title;
相关文章:
- Javascript-如何读取json文件中的列并将其保存在Javascript数组中
- 用于检查数组中是否存在元素的javascript自定义方法
- 验证会话中是否存在对象's数组
- 检查数组中是否存在字符串值,并返回找到的数组值js
- underline-js:将键对象与数组键对象进行比较,如果存在,则移除现有的添加新的
- 查找数组's按属性不存在于另一个数组中的对象
- 为什么没有从数组中存在的对象中删除属性
- 在对象上迭代以验证它是否's键存在于数组中
- 使用JQuery检查数组的索引中是否存在字符串
- JavaScript对象中存在数组的问题
- 使用javascript/jquery从现有数组中创建一个新数组,该数组保存项目存在的次数
- undercore返回数组中对象的indes,其中单词存在于对象中的句子中
- 如何使用函数来确定 Javascript 数组中是否存在值
- 如何将多个零推送到已经存在的数组
- 如何获取 JSON 数组下存在的相应值
- 仅当项目没有't存在于数组中
- 正在检查JavaScript中是否存在关联数组
- javascript中的数组和if语句存在问题
- 为什么JS需要对象/数组存在
- 如果数组存在于本地存储中,则返回false