Javascript Code Help.
- Started
- Last post
- 6 Responses
- ethanfink
Hey I am trying to get this little js file initiated on a wordpress site...
https://usefulapps.tech/select/
Don't know why I am having trouble, but I loaded this into the
<head>
<link rel="stylesheet" type="text/css" href="mydomain.com/usefulSelect.css" />in the <body>
<script type="text/javascript" src="mydomain.com/usefulSelect.js"></script>Which I believe is all firing ok, but this is where I am confused...
From the documentation:
Initialize your usefulSelect in your script file or an inline script tag
usefulSelect(".your-class", {
setting-name: setting-value
});Do I need to put script around this, and where should it go?
- ESKEMA1
You either put inside a <script> inside your html or you add it to an external .js file, after the loading line you already have
- ethanfink0
So like this?
<script type="text/javascript">
usefulSelect("select", {
useAdaptivePosition: 'center'
});</script>
I added this into a RAW JS field on my page builder...
So I am hoping to not have to install another plugin...
- Gnash2
(sorry for the thread hijack)
my son is looking into about learning some coding -- is javascript fairly future-friendly?
- For Web Development, yes it will be around for a long while. It also is use in other things, but the principles of coding work for many languages.BabySnakes
- I'd say get your son into HTML/CSS perhaps first to learn some basics, than introduce them to PHP/Javascript, so they're able to use computation a bit better.ideaist
- cheers. ya, he's looking at web development stuff.Gnash
- I never occurred to me that some of us are procreating into the industry.CyBrainX
- section_0140
You could use a map (hashmap), or just use an array of objects. The objects would have the advantage of being in JSON format natively. So, if you needed to send it to an API, it's ready to go. The map's main advantage is much faster lookup time.
Keep in mind: maps are not ordered. Each time you iterate over the map, the items could come up in a different order. So, if that's important, use objects.
- ^^^section_014
- Thanks.
The code already "maps" the original array :
{A: "A", 1], ["A", 3], ["A", 4]]}
I was thinking of Array.prototype.map to use chaining.palimpsest - your output is malformed btw
https://jsfiddle.net…dorf - I saw that, thanks.palimpsest
- I guess I'll stay with the tried and true for loop.palimpsest