I need to extract all unique IDs from foobar
elements on a page and create a comma-separated list. Here's an example:
<div>
<foobar id="456"></foobar>
<foobar id="aaa"></foobar>
<foobar id="987"></foobar>
<div>
This should result in "456,aaa,987"
The foobar
tags will not be nested.
Currently, I am using the following solution:
[].slice.call(document.getElementsByTagName("foobar")).map(function(a){return a.id}).join(","))
Is there a shorter way to achieve this in pure JavaScript, especially after minification?
Edit: Should work in ES5 (plain JavaScript)
Edit 2: Managed to reduce the code length with:
[].map.call(document.getElementsByTagName("foobar"),function(a){return a.id}).join();