项目背景需求是:
已知:
var a=[{name:'jenny',age:18},{name:'john',age:19},{name:'jack',age:20}]
var b ='jenny'
返回:
{name:'jenny',age:18}
解题思路:现将数组转成字符串,判断改数组中是否存在该字符串,存在的情况下遍历该数组,返回匹配的数据
代码如下:
项目背景需求是:
已知:
var a=[{name:'jenny',age:18},{name:'john',age:19},{name:'jack',age:20}]
var b ='jenny'
返回:
{name:'jenny',age:18}
解题思路:现将数组转成字符串,判断改数组中是否存在该字符串,存在的情况下遍历该数组,返回匹配的数据
代码如下: