diff --git a/Readme.md b/Readme.md index 36f96b5712..b7dcad2d74 100644 --- a/Readme.md +++ b/Readme.md @@ -624,14 +624,6 @@ $.xml() ### Miscellaneous DOM element methods that don't fit anywhere else -#### .toArray() -Retrieve all the DOM elements contained in the jQuery set, as an array. - -```js -$('li').toArray() -//=> [ {...}, {...}, {...} ] -``` - #### .clone() #### Clone the cheerio object. diff --git a/lib/api/manipulation.js b/lib/api/manipulation.js index bbab180fa8..7f201c6a74 100644 --- a/lib/api/manipulation.js +++ b/lib/api/manipulation.js @@ -13,7 +13,7 @@ var makeDomArray = function(elem) { if (elem == null) { return []; } else if (elem.cheerio) { - return elem.toArray(); + return elem.get(); } else if (_.isArray(elem)) { return _.flatten(elem.map(makeDomArray)); } else if (_.isString(elem)) { @@ -195,7 +195,7 @@ var html = exports.html = function(str) { return $.html(this[0].children); } - str = str.cheerio ? str.toArray() : evaluate(str); + str = str.cheerio ? str.get() : evaluate(str); domEach(this, function(i, el) { el.children = str; diff --git a/lib/api/traversing.js b/lib/api/traversing.js index 0fc0298185..2f22b60aa2 100644 --- a/lib/api/traversing.js +++ b/lib/api/traversing.js @@ -38,7 +38,7 @@ var parents = exports.parents = function(selector) { // When multiple DOM elements are in the original set, the resulting set will // be in *reverse* order of the original elements as well, with duplicates // removed. - this.toArray().reverse().forEach(function(elem) { + this.get().reverse().forEach(function(elem) { traverseParents(this, elem.parent, selector, Infinity) .forEach(function(node) { if (parentNodes.indexOf(node) === -1) { @@ -109,9 +109,9 @@ var nextUntil = exports.nextUntil = function(selector, filterSelector) { var elems = [], untilNode, untilNodes; if (typeof selector === 'string') { - untilNode = select(selector, this.nextAll().toArray())[0]; + untilNode = select(selector, this.nextAll().get())[0]; } else if (selector && selector.cheerio) { - untilNodes = selector.toArray(); + untilNodes = selector.get(); } else if (selector) { untilNode = selector; } @@ -171,9 +171,9 @@ var prevUntil = exports.prevUntil = function(selector, filterSelector) { var elems = [], untilNode, untilNodes; if (typeof selector === 'string') { - untilNode = select(selector, this.prevAll().toArray())[0]; + untilNode = select(selector, this.prevAll().get())[0]; } else if (selector && selector.cheerio) { - untilNodes = selector.toArray(); + untilNodes = selector.get(); } else if (selector) { untilNode = selector; } diff --git a/lib/cheerio.js b/lib/cheerio.js index bc1f7f94ee..d421f05a00 100644 --- a/lib/cheerio.js +++ b/lib/cheerio.js @@ -139,6 +139,8 @@ Cheerio.prototype._make = function(dom) { /** * Turn a cheerio object into an array + * + * @deprecated */ Cheerio.prototype.toArray = function() { diff --git a/test/api.manipulation.js b/test/api.manipulation.js index 7affc37c98..0d19110dbd 100644 --- a/test/api.manipulation.js +++ b/test/api.manipulation.js @@ -57,7 +57,7 @@ describe('$(...)', function() { it('(Array) : should append all elements in the array', function() { var $fruits = $(fruits); var more = $('