I have four input
<input type="text" class="kal" name="data[tex1]">
<input type="text" class="kal" name="data[tex2]">
<input type="text" class="kal" name="data[tex3]">
<input type="text" class="kal" name="data[tex4]">
Here is my jquery code :
var map = {};
$(".kal").each(function() {
map[$(this).attr("name")] = $(this).val();
});
console.log(map);
});
Now in console, I receive the result like this:
Object {data[tex1]: "ALI", data[tex2]: "JOHN", data[tex3]: "18", data[tex4]: "MOROCCO"}
How I can get values this object using jquery ?
FabioBranch
1754 silver badges20 bronze badges
asked Mar 14, 2017 at 13:42
-
I don't understand... you are getting the values by jQuery.evolutionxbox– evolutionxbox2017年03月14日 13:44:10 +00:00Commented Mar 14, 2017 at 13:44
1 Answer 1
You can access properties of object via bracket []
or .
syntax. In your case your map
is an object, but you can access it's properties via only []
syntax, because JavaScript Engine will give you error when you try to access with .
syntax,because those names are not valid for property for using with .
syntax.
Access via
map['data[tex1]']
Example
var map = {
'data[tex1]': 'AAA',
'data[tex2]': 'BBB',
'data[tex3]': 'CCC',
}; // After all your object will have this look
console.log(map['data[tex1]']);
// console.log(map.data[tex1]); this syntax will give you an error
answered Mar 14, 2017 at 13:43
Sign up to request clarification or add additional context in comments.
1 Comment
Shilly
Won't it be
map['data[tex1]']
, since the input names contain the string data[texX]
?lang-js