Skip to content

Commit

Permalink
Correctly iterate over a string.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Nov 16, 2019
1 parent 1ce33b5 commit 8cde069
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/array.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default function(x) {
return x == null ? [] : "length" in x ? x : Array.from(x);
return x == null ? [] // null, undefined
: typeof x === "object" && "length" in x ? x // Array, TypedArray, NodeList
: Array.from(x); // Map, Set, iterable, string, or anything else
}

0 comments on commit 8cde069

Please sign in to comment.