Skip to content

Instantly share code, notes, and snippets.

@IamManchanda
Last active November 28, 2018 11:33
Show Gist options
  • Save IamManchanda/8b8788fbe918be0c23b919db4ab30e6d to your computer and use it in GitHub Desktop.
Save IamManchanda/8b8788fbe918be0c23b919db4ab30e6d to your computer and use it in GitHub Desktop.
var obj = {
values: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34],
start: 4,
end: 13,
[Symbol.iterator]() {
var idx = this.start;
var end = this.end;
var it = {
next: () => {
if (idx <= end) {
var v = this.values[idx];
idx += 1;
return {
value: v,
done: false,
};
} else {
return {
value: undefined,
done: true,
};
}
}
};
return it;
},
};
var myCustomArr = [ ...obj ];
console.log(myCustomArr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment