I want to transfer the INI file content uploaded by users to an object and compare this object data with the existing one. Example INI file content is look like this:
Name: Aesthetic
Author: Redon
CursorCentre: 1
CursorExpand: 0
SliderBallFlip: 0
Combo1: 145,229,103
Combo2: 255,213,128
However when I tried to get object itself it is working. But when I tried to get value by key it doesn't work. How can I get value by key in this example?
$(document).on('change','input[name=import]',function(e){
var settings = {};
var file = e.target.files[0];
var reader = new FileReader();
reader.onload = function(){
var myText = reader.result;
var myText = myText.split(/\r?\n/);
$.each(myText, function(index, val) {
var item = val.split(":");
var itemkey = item[0];
var itemval = $.trim(item[1]);
settings[itemkey] = itemval;
});
}
reader.readAsText(file);
console.log(settings); // Works
console.log(settings['Author']); // undefined
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="file" name="import" accept=".ini">