eg:提取带有input中输入的值的数据,并处理其长度
<body><input type="txt" id="txt"><script>var arr =[{name:"你是谁,在哪里",id:1102},{name:"圈住你早那里",id:1102},{name:"hello foever see",id:1102},{name:"怪你",id:1102},{name:"world",id:1102},]var txt = document.getElementById("txt");txt.onkeydown =function(event){if(event.keyCode==13){var value =this.value;if(value!=""){var res =arr.filter(item=>{return item.name.includes(value);})res.map(item=>{if(item.name.length>3){return item.name =item.name.slice(0,3)+"..."}})console.log(res);}else alert("sorry can't find,NO content!")}}</script></body>
