EN
JavaScript - Uncaught ReferenceError: _ is not defined
1 answers
0 points
I've been trying to use underscore (_
) in my code and I've got a ReferenceError. Do you know how to fix it?
The error:
xxxxxxxxxx
1
Uncaught ReferenceError: _ is not defined
My code:
xxxxxxxxxx
1
2
<html>
3
<body>
4
<script>
5
6
var object = { id: 1, name: 'Mark' };
7
var array = _.values(object);
8
9
</script>
10
</body>
11
</html>
1 answer
0 points
You need to import underscore.js in your code.
The best way to do it is to create <head>
section in your code and import underscore.js there using a <script>
tag with CDN URL as a source.
Example <script>
with underscore.js v1.13.4 CDN URL:
xxxxxxxxxx
1
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/underscore@1.13.4/underscore-umd-min.js"></script>
Full example:
xxxxxxxxxx
1
2
<html>
3
<head>
4
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/underscore@1.13.4/underscore-umd-min.js"></script>
5
</head>
6
<body>
7
<script>
8
9
var object = { id: 1, name: 'Mark' };
10
var array = _.values(object);
11
12
</script>
13
</body>
14
</html>
Note:
Go to the Underscore.js site for more information and CDN URLs.
References
0 commentsShow commentsAdd comment