how to read HashMap in typescript 2.9
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
map = new Map<number, string>();
this.map.set(1, "educadmin");
this.map.set(6, "hr");
this.map.set(7, "tech");
console.log(map);
//process 1
for (let entry of this.map.entries()) {
console.log(entry[0], entry[1]);
}
//process 2
Array.from(map.values(), (value: string) => {
console.log(value);
});
I get this when I logged to the console:
Map(0) {}
size: (...)
__proto__: Map
[[Entries]]: Array(3)
0:{6 => "hr"}
1: {1 => "educadmin"}
2: {7 => "tech"}
length: 3
I want to add get all these values -> hr , educadmin and tech to a string
I tried above 2 process but I am not able to read
javascript angular6 typescript2.9
|
show 7 more comments
map = new Map<number, string>();
this.map.set(1, "educadmin");
this.map.set(6, "hr");
this.map.set(7, "tech");
console.log(map);
//process 1
for (let entry of this.map.entries()) {
console.log(entry[0], entry[1]);
}
//process 2
Array.from(map.values(), (value: string) => {
console.log(value);
});
I get this when I logged to the console:
Map(0) {}
size: (...)
__proto__: Map
[[Entries]]: Array(3)
0:{6 => "hr"}
1: {1 => "educadmin"}
2: {7 => "tech"}
length: 3
I want to add get all these values -> hr , educadmin and tech to a string
I tried above 2 process but I am not able to read
javascript angular6 typescript2.9
1
And your question is...?
– Jared Smith
Nov 16 '18 at 18:45
I am not able to read the values
– Rajesh Rajoji
Nov 16 '18 at 18:46
3
No luck with what? I'm voting to close this as unclear. Post the code you've tried, along with the desired output and error messages (if any), and I'll consider retracting my close vote. Also not clear at all what this has to do with typescript.
– Jared Smith
Nov 16 '18 at 18:51
2
Read what values? Again, please edit the question with a minimal, complete, verifiable example. Everything you've posted is disjointed and in some cases contradictory. Reading values out of a map is a simple as callingsomeMap.get(key)
, if it's not working something else is going on but you haven't posted enough for me to say. Your edit made it worse, not better.
– Jared Smith
Nov 16 '18 at 18:57
1
That's a huge step in the right direction. Now edit the output that you get from running your code into the question and why it isn't correct, becauseArray.from(map.values())
gives me["hr", "educadmin", "tech"]
.
– Jared Smith
Nov 16 '18 at 19:25
|
show 7 more comments
map = new Map<number, string>();
this.map.set(1, "educadmin");
this.map.set(6, "hr");
this.map.set(7, "tech");
console.log(map);
//process 1
for (let entry of this.map.entries()) {
console.log(entry[0], entry[1]);
}
//process 2
Array.from(map.values(), (value: string) => {
console.log(value);
});
I get this when I logged to the console:
Map(0) {}
size: (...)
__proto__: Map
[[Entries]]: Array(3)
0:{6 => "hr"}
1: {1 => "educadmin"}
2: {7 => "tech"}
length: 3
I want to add get all these values -> hr , educadmin and tech to a string
I tried above 2 process but I am not able to read
javascript angular6 typescript2.9
map = new Map<number, string>();
this.map.set(1, "educadmin");
this.map.set(6, "hr");
this.map.set(7, "tech");
console.log(map);
//process 1
for (let entry of this.map.entries()) {
console.log(entry[0], entry[1]);
}
//process 2
Array.from(map.values(), (value: string) => {
console.log(value);
});
I get this when I logged to the console:
Map(0) {}
size: (...)
__proto__: Map
[[Entries]]: Array(3)
0:{6 => "hr"}
1: {1 => "educadmin"}
2: {7 => "tech"}
length: 3
I want to add get all these values -> hr , educadmin and tech to a string
I tried above 2 process but I am not able to read
javascript angular6 typescript2.9
javascript angular6 typescript2.9
edited Nov 16 '18 at 19:41
Amy
22k1976133
22k1976133
asked Nov 16 '18 at 18:39
Rajesh RajojiRajesh Rajoji
13
13
1
And your question is...?
– Jared Smith
Nov 16 '18 at 18:45
I am not able to read the values
– Rajesh Rajoji
Nov 16 '18 at 18:46
3
No luck with what? I'm voting to close this as unclear. Post the code you've tried, along with the desired output and error messages (if any), and I'll consider retracting my close vote. Also not clear at all what this has to do with typescript.
– Jared Smith
Nov 16 '18 at 18:51
2
Read what values? Again, please edit the question with a minimal, complete, verifiable example. Everything you've posted is disjointed and in some cases contradictory. Reading values out of a map is a simple as callingsomeMap.get(key)
, if it's not working something else is going on but you haven't posted enough for me to say. Your edit made it worse, not better.
– Jared Smith
Nov 16 '18 at 18:57
1
That's a huge step in the right direction. Now edit the output that you get from running your code into the question and why it isn't correct, becauseArray.from(map.values())
gives me["hr", "educadmin", "tech"]
.
– Jared Smith
Nov 16 '18 at 19:25
|
show 7 more comments
1
And your question is...?
– Jared Smith
Nov 16 '18 at 18:45
I am not able to read the values
– Rajesh Rajoji
Nov 16 '18 at 18:46
3
No luck with what? I'm voting to close this as unclear. Post the code you've tried, along with the desired output and error messages (if any), and I'll consider retracting my close vote. Also not clear at all what this has to do with typescript.
– Jared Smith
Nov 16 '18 at 18:51
2
Read what values? Again, please edit the question with a minimal, complete, verifiable example. Everything you've posted is disjointed and in some cases contradictory. Reading values out of a map is a simple as callingsomeMap.get(key)
, if it's not working something else is going on but you haven't posted enough for me to say. Your edit made it worse, not better.
– Jared Smith
Nov 16 '18 at 18:57
1
That's a huge step in the right direction. Now edit the output that you get from running your code into the question and why it isn't correct, becauseArray.from(map.values())
gives me["hr", "educadmin", "tech"]
.
– Jared Smith
Nov 16 '18 at 19:25
1
1
And your question is...?
– Jared Smith
Nov 16 '18 at 18:45
And your question is...?
– Jared Smith
Nov 16 '18 at 18:45
I am not able to read the values
– Rajesh Rajoji
Nov 16 '18 at 18:46
I am not able to read the values
– Rajesh Rajoji
Nov 16 '18 at 18:46
3
3
No luck with what? I'm voting to close this as unclear. Post the code you've tried, along with the desired output and error messages (if any), and I'll consider retracting my close vote. Also not clear at all what this has to do with typescript.
– Jared Smith
Nov 16 '18 at 18:51
No luck with what? I'm voting to close this as unclear. Post the code you've tried, along with the desired output and error messages (if any), and I'll consider retracting my close vote. Also not clear at all what this has to do with typescript.
– Jared Smith
Nov 16 '18 at 18:51
2
2
Read what values? Again, please edit the question with a minimal, complete, verifiable example. Everything you've posted is disjointed and in some cases contradictory. Reading values out of a map is a simple as calling
someMap.get(key)
, if it's not working something else is going on but you haven't posted enough for me to say. Your edit made it worse, not better.– Jared Smith
Nov 16 '18 at 18:57
Read what values? Again, please edit the question with a minimal, complete, verifiable example. Everything you've posted is disjointed and in some cases contradictory. Reading values out of a map is a simple as calling
someMap.get(key)
, if it's not working something else is going on but you haven't posted enough for me to say. Your edit made it worse, not better.– Jared Smith
Nov 16 '18 at 18:57
1
1
That's a huge step in the right direction. Now edit the output that you get from running your code into the question and why it isn't correct, because
Array.from(map.values())
gives me ["hr", "educadmin", "tech"]
.– Jared Smith
Nov 16 '18 at 19:25
That's a huge step in the right direction. Now edit the output that you get from running your code into the question and why it isn't correct, because
Array.from(map.values())
gives me ["hr", "educadmin", "tech"]
.– Jared Smith
Nov 16 '18 at 19:25
|
show 7 more comments
1 Answer
1
active
oldest
votes
I think you are looking for a solution to get the keys/values as arrays.
let keysAsArray = Array.from(map.keys());
let valueAsArray = Array.from(map.values());
console.log(keysAsArray);
console.log(valueAsArray);
The output is
[1, 6, 7]
["educadmin", "hr", "tech"]
Yeah. I tried this way. But it does it work. I’m getting empty array. My typescript Version is 2.9 and using ecma 5. Do you feel that your code still supports these versions.
– Rajesh Rajoji
Nov 17 '18 at 1:03
1
Map
is introduced in ES6. You need to use polyfil. Can you take a look at this, this, and this to get more insights and eventually to solve your issue ?
– Charmis Varghese
Nov 17 '18 at 22:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343623%2fhow-to-read-hashmap-in-typescript-2-9%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you are looking for a solution to get the keys/values as arrays.
let keysAsArray = Array.from(map.keys());
let valueAsArray = Array.from(map.values());
console.log(keysAsArray);
console.log(valueAsArray);
The output is
[1, 6, 7]
["educadmin", "hr", "tech"]
Yeah. I tried this way. But it does it work. I’m getting empty array. My typescript Version is 2.9 and using ecma 5. Do you feel that your code still supports these versions.
– Rajesh Rajoji
Nov 17 '18 at 1:03
1
Map
is introduced in ES6. You need to use polyfil. Can you take a look at this, this, and this to get more insights and eventually to solve your issue ?
– Charmis Varghese
Nov 17 '18 at 22:14
add a comment |
I think you are looking for a solution to get the keys/values as arrays.
let keysAsArray = Array.from(map.keys());
let valueAsArray = Array.from(map.values());
console.log(keysAsArray);
console.log(valueAsArray);
The output is
[1, 6, 7]
["educadmin", "hr", "tech"]
Yeah. I tried this way. But it does it work. I’m getting empty array. My typescript Version is 2.9 and using ecma 5. Do you feel that your code still supports these versions.
– Rajesh Rajoji
Nov 17 '18 at 1:03
1
Map
is introduced in ES6. You need to use polyfil. Can you take a look at this, this, and this to get more insights and eventually to solve your issue ?
– Charmis Varghese
Nov 17 '18 at 22:14
add a comment |
I think you are looking for a solution to get the keys/values as arrays.
let keysAsArray = Array.from(map.keys());
let valueAsArray = Array.from(map.values());
console.log(keysAsArray);
console.log(valueAsArray);
The output is
[1, 6, 7]
["educadmin", "hr", "tech"]
I think you are looking for a solution to get the keys/values as arrays.
let keysAsArray = Array.from(map.keys());
let valueAsArray = Array.from(map.values());
console.log(keysAsArray);
console.log(valueAsArray);
The output is
[1, 6, 7]
["educadmin", "hr", "tech"]
answered Nov 16 '18 at 19:38
Charmis VargheseCharmis Varghese
906
906
Yeah. I tried this way. But it does it work. I’m getting empty array. My typescript Version is 2.9 and using ecma 5. Do you feel that your code still supports these versions.
– Rajesh Rajoji
Nov 17 '18 at 1:03
1
Map
is introduced in ES6. You need to use polyfil. Can you take a look at this, this, and this to get more insights and eventually to solve your issue ?
– Charmis Varghese
Nov 17 '18 at 22:14
add a comment |
Yeah. I tried this way. But it does it work. I’m getting empty array. My typescript Version is 2.9 and using ecma 5. Do you feel that your code still supports these versions.
– Rajesh Rajoji
Nov 17 '18 at 1:03
1
Map
is introduced in ES6. You need to use polyfil. Can you take a look at this, this, and this to get more insights and eventually to solve your issue ?
– Charmis Varghese
Nov 17 '18 at 22:14
Yeah. I tried this way. But it does it work. I’m getting empty array. My typescript Version is 2.9 and using ecma 5. Do you feel that your code still supports these versions.
– Rajesh Rajoji
Nov 17 '18 at 1:03
Yeah. I tried this way. But it does it work. I’m getting empty array. My typescript Version is 2.9 and using ecma 5. Do you feel that your code still supports these versions.
– Rajesh Rajoji
Nov 17 '18 at 1:03
1
1
Map
is introduced in ES6. You need to use polyfil. Can you take a look at this, this, and this to get more insights and eventually to solve your issue ?– Charmis Varghese
Nov 17 '18 at 22:14
Map
is introduced in ES6. You need to use polyfil. Can you take a look at this, this, and this to get more insights and eventually to solve your issue ?– Charmis Varghese
Nov 17 '18 at 22:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343623%2fhow-to-read-hashmap-in-typescript-2-9%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
And your question is...?
– Jared Smith
Nov 16 '18 at 18:45
I am not able to read the values
– Rajesh Rajoji
Nov 16 '18 at 18:46
3
No luck with what? I'm voting to close this as unclear. Post the code you've tried, along with the desired output and error messages (if any), and I'll consider retracting my close vote. Also not clear at all what this has to do with typescript.
– Jared Smith
Nov 16 '18 at 18:51
2
Read what values? Again, please edit the question with a minimal, complete, verifiable example. Everything you've posted is disjointed and in some cases contradictory. Reading values out of a map is a simple as calling
someMap.get(key)
, if it's not working something else is going on but you haven't posted enough for me to say. Your edit made it worse, not better.– Jared Smith
Nov 16 '18 at 18:57
1
That's a huge step in the right direction. Now edit the output that you get from running your code into the question and why it isn't correct, because
Array.from(map.values())
gives me["hr", "educadmin", "tech"]
.– Jared Smith
Nov 16 '18 at 19:25