You can try it on JSFiddler:
https://jsfiddle.net/AndrewBuntsev/8jbqyrv4/
['1', '7', '11'].map(parseInt);I surprisingly saw the result [1, NaN, 3] instead of [1, 7, 11]. But if we try parseFloat
['1', '7', '11'].map(parseFloat);the result is correct [1, 7, 11]
['1', '7', '11'].map(i => parseInt(i));we get the proper outcome as well.
<html>
<body>
<script>
function createString() {
return "0".repeat(25 * 1024 * 1024).substring(0, 12);
}
var arr = [];
setInterval(function() {
let str = createString();
arr.push(str);
}, 500);
</script>
</body>
</html>
run it in your browser and open the task manager you could notice that the browser takes some limited amount of memory ~200Mb. But what if we update one single digit in our code
return "0".repeat(25 * 1024 * 1024).substring(0, 13);i.e. replace 12 with 13, run it into a browser and have a look at the process memory. It grows unstoppable and makes the browser crash in a half a minute! Why does it happen?
<html>
<body>
<script>
function createString() {
return "0".repeat(25 * 1024 * 1024).substring(0, 12);
}
var arr = [];
setInterval(function() {
let str = createString().split('').join('');
arr.push(str);
}, 500);
</script>
</body>
</html>
That manoeuvre breaks the link with the original string and prevents memory leak.
const Users = React.lazy(() => import('./Users'));
render(
<div>
<Suspense fallback={<div>Loading...</div>}>
<Users />
</Suspense>
</div>
);
<input type="file" id="uploadVideoFile" accept="video/*" />So to access the chosen file we will call
var fileInput = document.getElementById("uploadVideoFile");
To display video we need a video element
div id="videoSourceWrapper">
<video style="width: 100%;" controls>
<source id="videoSource"/>
</video>
</div>
The following snippet displays the video after it is chosen in the video element for preview
$('#uploadVideoFile').on('change',
function() {
var fileInput = document.getElementById("uploadVideoFile");
console.log('Trying to upload the video file: %O', fileInput);
if ('files' in fileInput) {
if (fileInput.files.length === 0) {
alert("Select a file to upload");
} else {
var $source = $('#videoSource');
$source[0].src = URL.createObjectURL(this.files[0]);
$source.parent()[0].load();
$("#videoSourceWrapper").show();
}
} else {
console.log('No found "files" property');
}
}
);