我有一个字符串数组和一个字符串.我想针对数组值测试此字符串并应用条件结果 - 如果数组包含字符串do"A",否则执行"B".
我怎样才能做到这一点?
我正在查看Mozilla的代码,它为Array添加了一个过滤方法,它有一行代码让我很困惑.
var len = this.length >>> 0;
Run Code Online (Sandbox Code Playgroud)
我以前从未见过用于JavaScript的>>>.
它是什么,它做了什么?
在JavaScript中是否有一种方法可以获得字符串与正则表达式数组匹配的布尔值?
例子是('if'语句代表我想要实现的目标):
var thisExpressions = [ '/something/', '/something_else/', '/and_something_else/'];
var thisString = 'else';
if (matchInArray(thisString, thisExpressions)) {
}
Run Code Online (Sandbox Code Playgroud) 我想做的事情:正如标题中所述,我想设置一个单词的CSS,如果它是一个保留字.
<html>
<body>
<code id="java">
public static void main(String[] args)<br>
{
<pre> System.out.println("Hello World!");</pre>
}
</code>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
$(document).ready(function()
{
// Get the text inside the code tags
var code = $("#java").text();
// Split up each word
var split = code.split(' ');
// Array of reserved words
var array = ["abstract","assert","boolean","break","byte","case",
"catch","char","class","const","continue","default",
"do","double","else","else if","enum","extends","final",
"finally","float","for","goto","if","import","implements",
"instanceof","int","interface","long","native","new","null",
"package","private","protected","public","return","short",
"static","strictfp","super","switch","synchronized","this",
"throw","throws","transient","void","volatile","while"];
// Added when text contains a reserved word
var css = {'font-weight':'bold','color':'#2400D9'}
array = jQuery.map(array, function(n,i)
{
for …Run Code Online (Sandbox Code Playgroud) javascript ×4
arrays ×2
bit-shift ×1
css ×1
expression ×1
html ×1
jquery ×1
operators ×1
string ×1
testing ×1