I am trying to use map function in my code, but I am afraid that I am making some silly mistakes. It just does not work!
Here is my code. I have 2 buttons captioned "ID" and "Text". Clicking them should show the list of IDs and texts of the input field. The program works fine until the map.
Can you Gurus help me understand my mistake?
<!DOCTYPE html>
<html>
<head>
<script>
getID = (x) => x.id;
getText = (x) => x.value;
function Click(x) {
input = document.getElementsByTagName("input");
alert(input.map((x.id == "id") ? getID : getText));
}
</script>
</head>
<body>
<input type="input" id="input1"> </input>
<input type="input" id="input2"> </input>
<button id="id" onclick="Click(this)"> ID </button>
<button id="text" onclick="Click(this)"> Text </button>
</body>
</html>
input.map((x) => x.id === "id" ? getID(x) : getText(x))input.map(i => x.id === "id" ? getID(i) : getText(i)), not shadowing thexwhich refers to the button? Which would actually work the same as what the OP has already.