Сообщение от Замар
|
Он дает пустой массив.
|
???
<input type="text" id = "textarea" value = "Игорь">
<script>
let textarea = document.getElementById("textarea");
let list = [{name:"Вася",age:"23"},
{name:"Игорь", age:"25"}];
function filter(text, parameter){
let a = [];
for(let v of list){
if(v[parameter].indexOf(text) != -1)
a.push(v);
}
return a;
}
let b = filter(textarea.value, "name");
alert(JSON.stringify(b));
</script>
<input type="text" id = "textarea" value = "Игорь">
<script>
let textarea = document.getElementById("textarea");
let list = [{name:"Вася",age:"23"},
{name:"Игорь", age:"25"}];
function filter(list, text, parameter) {
return list.filter(el=>el[parameter].includes(text));
}
let b = filter(list ,textarea.value, "name");
alert(JSON.stringify(b));
</script>