I need to iterate over an array of html and return the ID, for example ['<div id="menu"></div>']
needs to return 'menu'
, ['<div id="online-menu">A La Carte</div>', '<div id="red-box">Welcome to the site</div>','<div id="hello">Hello</div>']
would return ['online-menu', 'red-box', 'hello']
my code so far is:
const getID = divs => {
const regex = /"[^"]*"/g
let returnedString = ''
while(returnedString = regex.exec(divs))
return returnedString
So I'm currently getting the following error:
AssertionError: expected [ Array(1) ] to deeply equal [ 'online-menu' ]
+ expected - actual[
- "\"online-menu\""
+ "online-menu"
]
Is anyone able to give me a nudge in the right direction, I have already tried .slice(1, -1)
which gave me an empty array if used before the return
statement and null
when used within the return
statement