0

I'm loading the name and id attributes of a <form> called contactForm to a javascript array like this:

const flds=[];
contactForm.querySelectorAll("input").
    forEach( value => { 
        flds.push([value.id, value.name])
    });
;
console.log(flds);

Can I do that directly without a loop? Something like:

const flds=contactForm.querySelectorAll("input [name,id]")

1 Answer 1

1

I think the best you can do is a map function.

const flds = [...contactForm.querySelectorAll("input")].map(el => [el.id, el.name])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.