> For the complete documentation index, see [llms.txt](https://note.niefee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://note.niefee.com/directory-1/ji-chu-bi-ji.md).

# 基础笔记

* [循环](https://note.niefee.com/directory-1/pages/-LjTb6eriWcpX-i9Ulsd#循环)
* [ECMAScript引用类型](https://note.niefee.com/directory-1/pages/-LjTb6eriWcpX-i9Ulsd#ecmascript引用类型)
  * [Object类型](https://note.niefee.com/directory-1/pages/-LjTb6eriWcpX-i9Ulsd#object类型)
  * [字符串类型](https://note.niefee.com/directory-1/pages/-LjTb6eriWcpX-i9Ulsd#字符串类型)
* [Global对象](https://note.niefee.com/directory-1/pages/-LjTb6eriWcpX-i9Ulsd#global对象)
* [Math对象](https://note.niefee.com/directory-1/pages/-LjTb6eriWcpX-i9Ulsd#math对象)
* [数组](https://note.niefee.com/directory-1/pages/-LjTb6eriWcpX-i9Ulsd#数组)
  * [检查数组](https://note.niefee.com/directory-1/pages/-LjTb6eriWcpX-i9Ulsd#检查数组)
  * [转换与排序](https://note.niefee.com/directory-1/pages/-LjTb6eriWcpX-i9Ulsd#转换与排序)
* [REPL命令](https://note.niefee.com/directory-1/pages/-LjTb6eriWcpX-i9Ulsd#repl命令)

## 循环

```javascript
outter: for (var i = 0; i < 3; i++) {
    inner:for (var j = 0; j < 4; j++) {
        if (i==2) {
            break outter;
        }
        console.log('i:',i,' j:',j);
    }
}
```

加上`outter`、`inner`这些**label**后，可以指定删除某个循环。

## ECMAScript引用类型

### Object类型

```javascript
var obj={name:"feeU"}
console.log(obj.name);
//"feeu"
```

### 字符串类型

`charCodeAt()`方法返回指定位置的字符的`Unicode`编码。 默认是0，可以指定位置。

`fromCharCode`是`String`的一个方法，把编码转换成字符串。

```javascript
var s="this is DieSSdki sile";

console.log(s.charCodeAt());
//116
console.log(String.fromCharCode(85));
//U
```

## Global对象

属性：

* Infinity
* NaN
* undefined
* null

方法：

* eval()
* isFinite()
* isNaN()
* parseFloat()
* parseInt()
* decodeURI()
* decodeURIComponent()
* encodeURI
* encodeURIComponent()

## Math对象

属性：

* Math.PI(圆周率)
* Math.E(自然数对数)

方法：

* Math.ceil()/Math.floor()/Math.round()
* Math.random()
* Math.max()/Math.min()

## 数组

### 检查数组

* Instanceof
* Array.isArray()

```javascript
var arr=[32,34,1,434,34]
//undefined
arr instanceof Array
//true
arr[2] instanceof Object
//false
Array.isArray(arr)
//true
```

### 转换与排序

* Object.keys(obj)

`Object.keys()`是`Object`的静态方法，把对象的`key`值转换成数组。

```javascript
var obj={a:1,b:23,c:"f"};

Object.keys(obj)
//['a','b','c']
```

* split()

把字符串安照指定内容分割成数组。

* toString()

把数组转换成字符串。

* join()

用指定内容拼接数组成一个新的字符串。

* sort()

按照字符串的序号排序数组。

* reserve()

反向排序。

* push()/pop()

向数组末尾添加或者删除一个元素。

* shift()/unshift()

向数组开头删除或者添加一个元素。

* concat()

把两个数组组合成一个数组。

* slice(a,b)

从数组中取出一定的元素，返回由取出元素组成的数组。

* splice()

从指定位置开始删除指定个数的数组，并在原来数组开头添加后续元素。

```javascript
var arr=[32,34,1,434,34]
//undefined
arr.splice(2,3,"hei","dogo")
[1, 434, 34]
arr
[32, 34, "hei", "dogo"]
```

* indexOf()/lastIndexOf()

查找指定元素的位置。

* every()

比较所有数组元素，所有为`true`就返回`true`。

```javascript
var arr=[32,34,1,434,34]
//undefined
var e=arr.every(function(m){return m>0;});
//undefined

e
//true
```

* some()

比较所有数组元素，只要有一个为`true`就返回`true`。

```javascript
var arr=[32,34,1,434,34]
undefined
var e=arr.some(function(m){return m>110;});
undefined
e
true
```

* filter()

返回符合要求的元素组成的数组。

```javascript
var arr=[1,4,563,2,5,4642,235,23];
undefined
var f=arr.filter(function(m){return m>10;})
//undefined

f
//[563, 4642, 235, 23]
```

* map()

对每个数组元素进行操作，返回由新元素组成的数组。

```javascript
var arr=[1,4,563,2,5,4642,235,23];
//undefined
var m=arr.map(function(m){return m+10;});
//undefined

m
//[11, 14, 573, 12, 15, 4652, 245, 33]
```

* array.forEach(callback\[, thisArg])

遍历、循环每一个数组元素。

**callback** 在数组每一项上执行的函数，接收三个参数：

1.currentValue

当前项（指遍历时正在被处理那个数组项）的值。

2.index

当前项的索引（或下标）。

3.array 数组本身。

**thisArg** 可选参数。用来当作callback 函数内this的值的对象。

* reduce()

这个方法用户迭代、递归。

```
arr.reduce(callback,[initialValue])
```

**callback**

执行数组中每个值的函数，包含四个参数：

1.previousValue 上一次调用回调返回的值，或者是提供的初始值（initialValue）

2.currentValue 数组中当前被处理的元素

3.index 当前元素在数组中的索引

4.array 调用 reduce 的数组

**initialValue** 作为第一次调用 callback 的第一个参数。

```javascript
[0,1,2,3,4].reduce(function(previousValue, currentValue, index, array){
  return previousValue + currentValue;
}, 10);

//20
```

* reduceRight()

与`reduce()`相似，顺序相反。

> **参考**:[mozilla](<https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce >)、[es5新增数组方法](http://www.zhangxinxu.com/wordpress/2013/04/es5%E6%96%B0%E5%A2%9E%E6%95%B0%E7%BB%84%E6%96%B9%E6%B3%95/)

## REPL命令

`REPL` — 交互式解释器环境。 `R(read)`、`E(evaluate)`、`P(print)`、`L(loop)`

输入值后，交互式解释器会读取输入内容并对它求值，再返回结果，并重复此过程。

* ctrl + c - 退出当前终端。
* ctrl + c 按下两次 - 退出 Node REPL。
* ctrl + d - 退出 Node REPL.
* 向上/向下 键 - 查看输入的历史命令
* tab 键 - 列出当前命令
* .help - 列出使用命令
* .break - 退出多行表达式
* .clear - 退出多行表达式
* .save filename - 保存当前的 Node REPL 会话到指定文件
* .load filename - 载入当前 Node REPL 会话的文件内容。
