Mad_Griffith Posted April 6, 2016 Share Posted April 6, 2016 (edited) I don't seem to get my head around the reason why the following returns TypeError: Object.values is not a function var input = '[a docs/my_pdf.pdf|here§my_class#my_id][img imgs/myimg.jpg|Alt title][g Artificial Languages][lang]HTML, CSS, Sass, SMACSS, SVG[y]7[/y][/lang][/g][p]Yes[/p]'; var RegEx = { 'tagClass': { '\§\s*(.+?)\s*[\§\|\]\#]': ' class="$1"' }, 'tagId': { '\#\s*(.+?)\s*[\§\|\]\#]': ' id="$1"' }, 'tagAlt': { '\[img.+?\|\s*(.+?)\s*[\§\|\]\#]': ' alt="$1"' }, 'tagTitle': { '\[a.+?\|\s*(.+?)\s*[\§\|\]\#]': ' title="$1"' }, 'tagSrc': { '\[img\s*(.+?)\s*[\§\|\]\#]': ' src="$1"' }, 'tagHref': { '\[a\s*(.+?)\s*[\§\|\]\#]': ' href="$1"' }, 'tagAngleBrackets': { '\[(\/?)(.+?(?=[\]]))\]?': '<$1$2>' } }; for (var tag in RegEx) { input.replace(new RegExp(Object.keys(RegEx[tag])[0], 'g'), Object.values(RegEx[tag])[0]); } Edited April 6, 2016 by Mad_Griffith Link to comment Share on other sites More sharing options...
justsomeguy Posted April 6, 2016 Share Posted April 6, 2016 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values Scroll to the bottom and check the compatibility table. Link to comment Share on other sites More sharing options...
Mad_Griffith Posted April 6, 2016 Author Share Posted April 6, 2016 (edited) Ah, I see the second param should be a callback func. Is there any way to have the Object.values bit evaluated as a func? edit: @justsomeguy, thanks! Could you suggest an alternative solution? Edited April 6, 2016 by Mad_Griffith Link to comment Share on other sites More sharing options...
justsomeguy Posted April 6, 2016 Share Posted April 6, 2016 Save they key, and use that to get the value. Link to comment Share on other sites More sharing options...
Mad_Griffith Posted April 6, 2016 Author Share Posted April 6, 2016 I don't get the notation I should use... I am doing some tests but I am stuck, e.g., at Object.keys(RegEx["tagClass"]) and cannot proceed... Link to comment Share on other sites More sharing options...
justsomeguy Posted April 6, 2016 Share Posted April 6, 2016 var key = Object.keys(RegEx["tagClass"])[0]; var val = RegEx["tagClass"][key]; Link to comment Share on other sites More sharing options...
Mad_Griffith Posted April 7, 2016 Author Share Posted April 7, 2016 Thanks! I had it work with this nested loop, too for (var j in RegEx[i]) { return RegEx[i][j] } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now