- 👋 Hi, I’m @the-one-with-raspberry
- 👀 I’m interested in javascript
- 🌱 I’m currently learning nothing
- 📫 [email protected]
- https://www.youtube.com/channel/UCxGHpsV2VBI4fNgM7VMnflg
a cool script that i wrote:
function mapCharStringToJSON(string) {
const strCharArray = string.split('');
let JSONobj = {};
let i = 0;
for (let char of strCharArray) {
JSONobj[char] = i;
i = i + 1;
}
return JSONobj;
}
const exampleStr = 'henlo';
console.log(JSON.stringify(mapCharStringToJSON(exampleStr)));
// returns: {"h":0,"e":1,"n":2,"l":3,"o":4}
// strings with repeated characters dont work :(