I am using the below code to read the properties of a web-part using JSOM. While i can read the properties of the web-parts that are there on the current web part page, I would like to know of a way that would allow me to do this without looping through all the web-parts on that page. The looping happens in the code section starting with
while (webParts1.moveNext()){...}
function init() {
var ctx = new SP.ClientContext();
var pageFile = ctx.get_web().getFileByServerRelativeUrl('/SitePages/TestWebProp.aspx');
var limitedwpMangager = pageFile.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared)
var webParts = limitedwpMangager.get_webParts();
ctx.load(webParts);
ctx.executeQueryAsync(function () {
var webParts1 = webParts.getEnumerator();
while (webParts1.moveNext()) {
var webpart = webParts1.get_current();
var prop = webpart.get_webPart().get_properties();
ctx.load(prop);
ctx.executeQueryAsync(function () {
console.log(prop.get_item('Title'));
},CommonError)
}
},CommonError)
}
function CommonError(){
console.log("Something went wrong");
}
ExecuteOrDelayUntilScriptLoaded(init, 'sp.js')