Hello
I’ve created script which use function adding atributes to one object and I have problem cause I can’t get attributes from array of objects
and set this elements to one object. I’ve tryed by mapping and forEach loop
CODE:
import React from "react";
import ReactDOM from 'react-dom/client';
import { useState } from 'react';
function AttributeFromList(){
const listOfAttributes = [
{nameOfAttribute: "class_of_car", valueOfAttribute: "economy_car"},
{nameOfAttribute: "color_of_car", valueOfAttribute: "red"},
{nameOfAttribute: "year_of_production", valueOfAttribute: 2010},
]
const executeEvent = (elem, attr) => {
listOfAttributes.keys(attr).forEach( ev => {
elem.target.setAttribute(ev, listOfAttributes[ev]);
});
}
return(
<div>
<button onClick={executeEvent}>Run</button>
</div>
)
}
const execute = ReactDOM.createRoot(document.getElementById(('root')));
execute.render(<AttributeFromList />)