function PrintArray (arr) {
for (var i in arr) {
if (Arr[i] instance of Array) {
PrintArray (Arr[i]);
}else{
document.write (arr[i]+ ");
}
}
}
var data=[1,[20,21],[[301,302],[310,[311]];
PrintArray (data);
After the above code is run, the page output is?
Answer: 1 20 21 301 302 310 311
The function PrintArray uses recursion to output each member of the array one by one, separated by a space
The instanceof operator is used to test whether an object has a prototype property of a constructor in its prototype chain
What is a stack?
A stack is a linear table with limited operations, and the term system allows only one end of the table to insert and delete operations. This end is called the top of the stack, and the opposite end is called the bottom of the stack. Inserting a new element into a stack, also known as a stack, into a stack, or a stack, is to put the new element above the top of the stack, making it a new stack top element, the deletion of elements from a stack, called a stack or a stack, it is to remove the top element of the stack, so that its adjacent elements are called the new top
Push, press in from the end
Pop, remove from end
Shift, DELETE from first
Unshift from First press in
What is a regular expression? How do I use regular expressions?
The regular expression itself is a string, consisting of some ordinary string and a special string of expressions that describe a particular character rule.
There are two kinds of application of the expression in JavaScript;
1, combined with the Replace search match method of the string object, implements the substitution, finding and matching of strings;
2, defines the regular expression object, implements the complex matching operation to the string.
Varregexp=/\bdo\b/ig;
VarData=' He does told to Do,do. ';
Console. log (data. Search (regexp));
Output 16
\b Represents the letter boundary
IG is usually linked together
Indicates case insensitive. G means looking from beginning to end.
Search indicates that the index is returned after it is found
Read the following code
function Add (num) {
try{
Num=number (num);
if (IsNaN (num) {
throw new Error (' Argument is NaN ');
}
Console.log (' Try block end ');
}catch (e) {
Console.log (' catch block ');
Return
}finally{
Console.log (' finally block ');
}console.log (' function end ');
}
Add (' 10x ');
Ask the above code to run, the output is?
Answer:
First, the catch block is output and the finally block
Because a try Catch statement is a statement that is used as an exception handler, a catch is taken after a program error
So the output catch block;
The finally will always run, so the output continues. When an exception occurs, the program is rolled out, so no more statements are executed.
JS Basic question