Skip to content

Commit a2c73e4

Browse files
authored
Create DestructureArray.js
1 parent af0b0bb commit a2c73e4

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎Array/DestructureArray.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const destructure = function(obj = {}){
2+
return this.map((value, key) => obj[key] = value) && obj;
3+
};
4+
5+
Array.prototype.destructure = destructure;
6+
7+
// example
8+
// var arr = ["Paulo", "Sergio", "Junior"];
9+
// const { 0: nome, 1: meio, 2: final, inject } = arr.destructure({ inject: "injetado" });
10+
// console.log({ nome, meio, final, inject })
11+
12+
// example ( module.exports )
13+
// var arr = ["Paulo", "Sergio", "Junior"];
14+
// const { 0: nome } = prototip(arr)();
15+
// console.log({ nome });
16+
17+
module.exports = arr => destructure.bind(arr);

0 commit comments

Comments
 (0)