How to remove the matching element of the array

This question already has an answer here: How do I remove a particular element from an array in JavaScript? 63 answers 找到单词的索引,然后使用拼接将其从阵列中删除。 var array = ['html', 'css', 'perl', 'c', 'java', 'javascript'] var index = array.indexOf('perl'); if (index > -1) { array.splice(index, 1); } if you want to just delete the value in the array and leave the spot undefin

如何删除数组的匹配元素

这个问题在这里已经有了答案: 如何从JavaScript中的数组中删除特定的元素? 63个答案 找到单词的索引,然后使用拼接将其从阵列中删除。 var array = ['html', 'css', 'perl', 'c', 'java', 'javascript'] var index = array.indexOf('perl'); if (index > -1) { array.splice(index, 1); } 如果您只想删除数组中的值并将该点保留为未定义的而不是具有该字符串: var arr =['html', 'css', 'perl', 'c', 'java',

Remove a Single Object from a Javascript Object

This question already has an answer here: How do I remove a particular element from an array in JavaScript? 63 answers javascript - remove array element on condition 5 answers Iteration is a must. You have to use .splice() to remove corresponding item and break the for loop. var i, id = '123', date = '6/7/2010'; for(var i = 0, il = MyCheckedCourses.length;i<il;i++) { if(MyCheckedC

从Javascript对象中删除单个对象

这个问题在这里已经有了答案: 如何从JavaScript中的数组中删除特定的元素? 63个答案 JavaScript的 - 条件5答案删除数组元素 迭代是必须的。 您必须使用.splice()来删除相应的项目并break for循环。 var i, id = '123', date = '6/7/2010'; for(var i = 0, il = MyCheckedCourses.length;i<il;i++) { if(MyCheckedCourses[i].courseID == id && MyCheckedCourses[i].endDate == date) { MyCheck

How to remove specific element in array in javascript

This question already has an answer here: How do I remove a particular element from an array in JavaScript? 63 answers var newArray = []; var a=["a","b","c"]; for(var i=0;i<a.length;i++) if(a[i]!=="a") newArray.push(a[i]); remove = function(ary, elem) { var i = ary.indexOf(elem); if (i >= 0) ary.splice(i, 1); return ary; } provided your target browser suppports array.in

如何在javascript中删除数组中的特定元素

这个问题在这里已经有了答案: 如何从JavaScript中的数组中删除特定的元素? 63个答案 var newArray = []; var a=["a","b","c"]; for(var i=0;i<a.length;i++) if(a[i]!=="a") newArray.push(a[i]); remove = function(ary, elem) { var i = ary.indexOf(elem); if (i >= 0) ary.splice(i, 1); return ary; } 前提是您的目标浏览器支持array.indexOf ,否则使用array.indexOf的后备代码。 如果您需

Opposite of push();

This question already has an answer here: How do I remove a particular element from an array in JavaScript? 63 answers Well, you've kind of asked two questions. The opposite of push() (as the question is titled) is pop() . var exampleArray = ['myName']; exampleArray.push('hi'); console.log(exampleArray); exampleArray.pop(); console.log(exampleArray); push() adds at end; pop() de

push()相反;

这个问题在这里已经有了答案: 如何从JavaScript中的数组中删除特定的元素? 63个答案 那么,你有两个问题。 push() (与问题标题相同)是pop() 。 var exampleArray = ['myName']; exampleArray.push('hi'); console.log(exampleArray); exampleArray.pop(); console.log(exampleArray); push()在最后添加; pop()从结束删除。 unshift()添加到前面; shift()从前面删除。 splice()可以splice()执行任何操作。

When is a CDATA section necessary within a script tag?

Are CDATA tags ever necessary in script tags and if so when? In other words, when and where is this: <script type="text/javascript"> //<![CDATA[ ...code... //]]> </script> preferable to this: <script type="text/javascript"> ...code... </script> A CDATA section is required if you need your document to parse as XML (eg when an XHTML page is interpreted as XML) an

在脚本标记中何时需要CDATA部分?

CDATA标签在脚本标签中是否有必要,如果是的话? 换句话说,何时何地是这样的: <script type="text/javascript"> //<![CDATA[ ...code... //]]> </script> 更可取的是: <script type="text/javascript"> ...code... </script> 如果需要将文档解析为XML(例如,当将XHTML页面解释为XML),并且希望能够写入文字i<10和a && b而不是i&lt;10和a &amp;&amp; b a &

How to check for specific string in a dictionary?

I have a dictionary like: a = {"staticData":['----','Blue','Green'], "inData":['Indatahere','----','----']} How can I find that if the dictionary contains "----", in any of the key's values. Any Javascript function? EDIT: What if the case is like this? a = {"staticData":[], "inData":['Indatahere','----','----']} It's giving this Error: TypeError: a[elem].indexOf is not

如何检查字典中的特定字符串?

我有一本字典,如: a = {"staticData":['----','Blue','Green'], "inData":['Indatahere','----','----']} 我怎么能发现,如果字典包含“----”,在任何键的值。 任何Javascript功能? 编辑:如果案件是这样的呢? a = {"staticData":[], "inData":['Indatahere','----','----']} 它给这个错误: TypeError: a[elem].indexOf is not a function 代码如下: var a = {"staticData":['----','Blue','Green'], "inData":['

Why indexOf in javascript not working?

I'm not sure what I'm doing wrong here. The first instance that I use indexOf it works perfectly fine, but when I use it the second time it's not returning the result that I'm expecting. function mutation(arr) { //return arr; res = ""; for (var x=0; x<arr[1].split("").length; x++) { if (arr[0].indexOf(arr[1].split("")[x]) !== -1) { res += "t";

为什么indexOf在JavaScript中不起作用?

我不确定我在这里做错了什么。 我使用indexOf的第一个实例工作得很好,但是当我第二次使用它时,它没有返回我期待的结果。 function mutation(arr) { //return arr; res = ""; for (var x=0; x<arr[1].split("").length; x++) { if (arr[0].indexOf(arr[1].split("")[x]) !== -1) { res += "t"; } else { res += "f"; } } // res = ttt if (res.in

what is the alternate function for indexOf for string in IE8?

I have used indexOf to check whether i have particular text is present in a sentence or not like the following var temp = ""; temp="data not available"; if(temp.indexOf("datas") == 0){ alert("True"); } else{ alert("false"); } The problem i was facing is indexOf is not supported in Internet Explorer 8 . How to perform this operation in IE8 too? Is there any default alternate functions

在IE8中,indexOf用于字符串的替代函数是什么?

我用indexOf来检查我是否有特定的文本出现在一个句子中,或者不是像下面这样 var temp = ""; temp="data not available"; if(temp.indexOf("datas") == 0){ alert("True"); } else{ alert("false"); } 我遇到的问题是Internet Explorer 8中不支持indexOf 。 如何在IE8中执行此操作? jQuery中有没有默认的备用函数 ? 我尝试了inArray,但它只支持数组。 小提琴 我认为你对哪个indexOf()被支持感到困惑。 根

Why is indexOf not working in Internet Explorer?

This function executes during the forms onSubmit, and works fine in Firefox and Chrome, but not in IE. I suspect it's indexOf, but I cannot seem to find a way to get it to work. function checkSuburbMatch(e) { var theSuburb = document.getElementById('suburb').value; var thePostcode = document.getElementById('postcode').value; var arrayNeedle = theSuburb + " (" + thePostcode + ")"; if(subu

为什么indexOf在Internet Explorer中不起作用?

这个函数在onSubmit表单中执行,并在Firefox和Chrome中正常工作,但在IE中不起作用。 我怀疑它是indexOf,但我似乎无法找到一种方法来实现它。 function checkSuburbMatch(e) { var theSuburb = document.getElementById('suburb').value; var thePostcode = document.getElementById('postcode').value; var arrayNeedle = theSuburb + " (" + thePostcode + ")"; if(suburbs.indexOf(arrayNeedle) != -1) { alert("Sub

how to make it work

This question already has an answer here: Why doesn't indexOf work on an array IE8? 7 answers jQuery provides inArray for arrays so you can avoid using the array version of indexOf (not present in IE8). Two of your other examples are using the string version of indexOf which does exist in IE8.

如何使它工作

这个问题在这里已经有了答案: 为什么indexOf不能在数组IE8上工作? 7个答案 jQuery为数组提供了inArray,因此您可以避免使用indexOf的数组版本(不存在于IE8中)。 其他两个示例使用IE8中存在的indexOf字符串版本。