JSโฉ iteration โฉ iterable โฉ extension โฉ obj.isIterable
check if an object is iterable.
array.isIterable, // true object.isIterable, // false (3).isIterable, // false
replit โฉ Iterable (protocol)
Object.defineProperties(Object.prototype, { // โญ๏ธ obj.isIterable isIterable: { get() { // โญ๏ธ code copied from the chat bot "chatGPT" return typeof this[Symbol.iterator] === 'function'; } }, }
Symbol.iterator - "make-iterator" method name.
Object.defineProperty() - define new properties.
JavaScript: The Definitive Guide โฉ 12.2 Implementing Iterable Objects
Last updated 2 years ago
Was this helpful?