In JavaScript, how would I take the values of an object and add each one as a separate class on an element in the DOM?
For instance, let's say I have this object:
const METADATA = {
foo: 'test1',
bar: 'test2'
};
I want to add the values present within this object as two separate classes on the <html>
tag.
In order to achieve this, I tried to specify the properties of the METADATA object within the jQuery .addClass
method:
$('html').addClass( METADATA["foo","bar"] );
But this only added the last value of the object as a class on the <html>
tag, which has left me fairly confused.
Any thoughts?