I'd like to use array as data-* attribute and a lot of StackOverflow answers suggest that I should use JSON.stringify();
- How to pass an array into jQuery .data() attribute
- Store and use an array using the HTML data tag and jQuery
- https://gist.github.com/charliepark/4266921
- etc.
So, if I have this array: ['something', 'some\'thing', 'some"thing'] it will be parsed to "["something","some'thing","some\"thing"]" and therefore it won't fit neither data-*='' nor data-*="" because either ' or " will break the HTML tag.
Am I missing something or encodeURIComponent() is a true solution to encoding arrays like that? Why in other StackOverflow answers nobody noticed this?