🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# [For of](https://babeljs.cn/docs/plugins/transform-es2015-for-of) 在 ES6 中可以使用 for-of 遍历数组,可以使用 `babel-plugin-transform-es2015-for-of` 进行语法转换。 ``` npm install --save-dev babel-plugin-transform-es2015-for-of ``` ## .babelrc 配置 ```json { "plugins": ["transform-es2015-for-of"] } ``` ## 使用 in ```js let arr = ['a', 'b', 'c'] for (var i of arr) { console.log(i) } ``` out ```js 'use strict'; var arr = ['a', 'b', 'c']; var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = arr[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var i = _step.value; console.log(i); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } ```